Skip to content

Commit 877f919

Browse files
Chunyu-HuAl Viro
authored andcommitted
proc: add proc_seq_release
kmemleak reported some memory leak on reading proc files. After adding some debug lines, find that proc_seq_fops is using seq_release as release handler, which won't handle the free of 'private' field of seq_file, while in fact the open handler proc_seq_open could create the private data with __seq_open_private when state_size is greater than zero. So after reading files created with proc_create_seq_private, such as /proc/timer_list and /proc/vmallocinfo, the private mem of a seq_file is not freed. Fix it by adding the paired proc_seq_release as the default release handler of proc_seq_ops instead of seq_release. Fixes: 44414d8 ("proc: introduce proc_create_seq_private") Reviewed-by: Christoph Hellwig <[email protected]> CC: Christoph Hellwig <[email protected]> Signed-off-by: Chunyu Hu <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent ce397d2 commit 877f919

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/proc/generic.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,20 @@ static int proc_seq_open(struct inode *inode, struct file *file)
564564
return seq_open(file, de->seq_ops);
565565
}
566566

567+
static int proc_seq_release(struct inode *inode, struct file *file)
568+
{
569+
struct proc_dir_entry *de = PDE(inode);
570+
571+
if (de->state_size)
572+
return seq_release_private(inode, file);
573+
return seq_release(inode, file);
574+
}
575+
567576
static const struct file_operations proc_seq_fops = {
568577
.open = proc_seq_open,
569578
.read = seq_read,
570579
.llseek = seq_lseek,
571-
.release = seq_release,
580+
.release = proc_seq_release,
572581
};
573582

574583
struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,

0 commit comments

Comments
 (0)