在對內核泄漏進行靜態分析時,我遇到了一個有趣的場景,我無法找到變量的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