在对内核泄漏进行静态分析时,我遇到了一个有趣的场景,我无法找到变量的de分配。 分配在以下功能发生(使用kmalloc的调用),如下:linux内核中潜在的内存泄漏?
static int mounts_open_common(struct inode *inode, struct file *file,
int (*show)(struct seq_file *, struct vfsmount *)){
struct proc_mounts *p;
//some code//
*p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);**
file->private_data = &p->m;//the allocated variable is escaped to file structure
//some code
}
我希望这个分配的内存固定在:
static int mounts_release(struct inode *inode, struct file *file)
{
struct proc_mounts *p = proc_mounts(file->private_data);
path_put(&p->root);
put_mnt_ns(p->ns);
return seq_release(inode, file);
}
但似乎这个功能访问分配变量来释放一些内部成员,但不是变量'p'本身。 那么这个变量的内存在哪里被释放?如果它应该在mounts_release函数中释放,那么它可能会发生内存泄漏。
什么是seq_release(inode,file);电话呢? – 2014-09-26 19:01:25
据我所知,mounts_release()函数应该释放与挂载设备相关的内存! – dsingh 2014-09-26 19:04:41