3
我在linux内核(2.4)的一些代码上工作,出于某种原因,kmalloc返回相同的地址(我相信它只发生在测试的中间) 。我检查了在调用kmalloc之间没有调用kfree(即内存仍在使用中)。kmalloc一遍又一遍地返回相同的地址[Linux 2.4]
也许我内存不足? (kmalloc没有返回NULL ...)
关于如何发生这种事情的任何想法?
在此先感谢您的帮助!
代码:
typedef struct
{
char* buffer;
int read_count;
int write_count;
struct semaphore read_sm;
struct semaphore write_sm;
int reader_ready;
int writer_ready;
int createTimeStamp;
} data_buffer_t ;
typedef struct vsf_t vsf_t;
struct vsf_t
{
int minor;
int type;
int open_count;
int waiting_pid;
data_buffer_t* data;
list_t proc_list;
vsf_t* otherSide_vsf;
int real_create_time_stamp;
};
int create_vsf(struct inode *inode, struct file *filp, struct vsf_command_parameters* parms)
{
...
buff_data = allocate_buffer();
if (buff_data == NULL)
{
kfree(this_vsfRead);
kfree(this_vsfWrite);
return -ENOMEM;
}
...
}
data_buffer_t* allocate_buffer()
{
...
data_buffer_t* this_buff = (data_buffer_t*)kmalloc(sizeof(data_buffer_t), GFP_KERNEL);
if (this_buff == NULL)
{
printk(KERN_WARNING "failure at allocating memory\n");
return NULL;
}
...
return this_buff;
}
*我每次打印的kmalloc和kfree后,我绝对相信没有kfree被称为用kmalloc的(即返回同一个地址)之间
发现它,双倍免费! – Belgi