【发布时间】:2014-09-26 18:56:32
【问题描述】:
在对 linux 内核进行内存泄漏的静态分析时,我遇到了一个有趣的场景,我无法找到变量的解除分配。 分配发生在以下函数中(使用 kmalloc 调用),如下所示:
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);打电话吗?
-
据我所知,mounts_release() 函数应该释放与已安装设备相关的内存!
标签: c linux memory-leaks linux-kernel