While doing static analysis of linux kernel for memory leaks, I came across an interesting scenario where i am not able to find the de allocation of a variable. The allocation is happening in the following function(using kmalloc call) as below:
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
}
I expect this allocated memory to be fixed at:
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);
}
But it seems this function is accessing the allocated variable to free some its internel members but not the variable 'p' itself. So where is this variable's memory is freed? If it is supposed to free in mounts_release function then its a potential memory leak.