From: Satyam Sharma <satyam@infradead.org>
To: Alexey Dobriyan <adobriyan@sw.ru>
Cc: akpm@osdl.org, viro@ftp.linux.org.uk,
linux-kernel@vger.kernel.org, devel@openvz.org, mingo@elte.hu
Subject: Re: [PATCH] single_open/seq_release leak diagnostics
Date: Thu, 2 Aug 2007 12:24:05 +0530 (IST) [thread overview]
Message-ID: <alpine.LFD.0.999.0708021217370.8258@enigma.security.iitk.ac.in> (raw)
In-Reply-To: <20070731120526.GA6883@localhost.sw.ru>
Hi,
On Tue, 31 Jul 2007, Alexey Dobriyan wrote:
> [...]
> --- a/fs/seq_file.c
> +++ b/fs/seq_file.c
> @@ -281,6 +281,13 @@ EXPORT_SYMBOL(seq_lseek);
> int seq_release(struct inode *inode, struct file *file)
> {
> struct seq_file *m = (struct seq_file *)file->private_data;
> +
> + if (m->seq_ops_allocated) {
> + struct dentry *dentry = file->f_dentry;
> + printk("memory leak: '%.*s'\n",
> + dentry->d_name.len, dentry->d_name.name);
> + WARN_ON(1);
> + }
> kfree(m->buf);
> kfree(m);
> return 0;
> @@ -401,9 +408,12 @@ int single_open(struct file *file, int (*show)(struct seq_file *, void *),
> op->stop = single_stop;
> op->show = show;
> res = seq_open(file, op);
> - if (!res)
> - ((struct seq_file *)file->private_data)->private = data;
> - else
> + if (!res) {
> + struct seq_file *seq = file->private_data;
> +
> + seq->private = data;
> + seq->seq_ops_allocated = 1;
> + } else
> kfree(op);
> }
> return res;
> @@ -412,8 +422,13 @@ EXPORT_SYMBOL(single_open);
>
> int single_release(struct inode *inode, struct file *file)
> {
> - const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
> - int res = seq_release(inode, file);
> + struct seq_file *seq = file->private_data;
> + const struct seq_operations *op = seq->op;
> + int res;
> +
> + /* All roads lead to seq_release(), so... */
> + seq->seq_ops_allocated = 0;
> + res = seq_release(inode, file);
> kfree(op);
> return res;
> }
> --- a/include/linux/seq_file.h
> +++ b/include/linux/seq_file.h
> @@ -22,6 +22,7 @@ struct seq_file {
> struct mutex lock;
> const struct seq_operations *op;
> void *private;
> + unsigned int seq_ops_allocated:1;
> };
>
> struct seq_operations {
Hmm, curiously, I think this patch just killed the utility of having
single_release() around in the first place :-)
We might as well free the seq_file->op when we detect that we're
leaking it in seq_release() itself. That makes single_release() wholly
redundant to keep, and we can just convert all its users to seq_release()
itself. With less of these around, lesser probability of someone coding
a bug/leak in the first place!
Just my Rs. 0.02,
Satyam
prev parent reply other threads:[~2007-08-02 6:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-31 12:05 Alexey Dobriyan
2007-08-02 6:54 ` Satyam Sharma [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.0.999.0708021217370.8258@enigma.security.iitk.ac.in \
--to=satyam@infradead.org \
--cc=adobriyan@sw.ru \
--cc=akpm@osdl.org \
--cc=devel@openvz.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=viro@ftp.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®