linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Adam J. Richter" <adam@yggdrasil.com>
To: maneesh@in.ibm.com
Cc: akpm@osdl.org, chrisw@osdl.org, greg@kroah.com,
	linux-kernel@vger.kernel.org,
	viro@parcelfarce.linux.theplanet.co.uk
Subject: [PATCH 2.6.10-rc2-bk15] sysfs_dir_close memory leak
Date: Thu, 2 Dec 2004 18:50:35 -0800	[thread overview]
Message-ID: <200412030250.iB32oZQ02969@adam.yggdrasil.com> (raw)

	sysfs_dir_close did not free the "cursor" sysfs_dirent
used for keeping track of position in the list of sysfs_dirent nodes.
Consequently, doing a "find /sys" would leak a sysfs_dirent for
each of the 1140 directories in my /sys tree, or about 36kB
each time.

	This patch was generated against a sysfs tree with a
bunch of other changes, but should apply to the stock Linux tree
with the appropriate line number adjustments.

	If this patch looks OK, I would appreciate it if someone
would forward it downstream for integration.

                    __     ______________
Adam J. Richter        \ /
adam@yggdrasil.com      | g g d r a s i l


diff -u9 linux.prev/fs/sysfs/dir.c linux.noleak/fs/sysfs/dir.c
--- linux.prev/fs/sysfs/dir.c	2004-12-02 14:51:01.000000000 +0800
+++ linux.noleak/fs/sysfs/dir.c	2004-12-03 10:42:06.000000000 +0800
@@ -346,18 +346,21 @@
 static int sysfs_dir_close(struct inode *inode, struct file *file)
 {
 	struct dentry * dentry = file->f_dentry;
 	struct sysfs_dirent * cursor = file->private_data;
 
 	down(&dentry->d_inode->i_sem);
 	list_del_init(&cursor->s_sibling);
 	up(&dentry->d_inode->i_sem);
 
+	BUG_ON(cursor->s_dentry != NULL);
+	release_sysfs_dirent(cursor);
+
 	return 0;
 }
 
 /* Relationship between s_mode and the DT_xxx types */
 static inline unsigned char dt_type(struct sysfs_dirent *sd)
 {
 	return (sd->s_mode >> 12) & 15;
 }
 

             reply	other threads:[~2004-12-03  3:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-03  2:50 Adam J. Richter [this message]
2004-12-03  5:19 ` [PATCH 2.6.10-rc2-bk15] sysfs_dir_close memory leak Chris Wright
2004-12-03 11:05   ` Adam J. Richter
2004-12-03 18:56     ` Greg KH
2004-12-04  2:39 Adam J. Richter
2004-12-04  7:35 ` Chris Wright

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=200412030250.iB32oZQ02969@adam.yggdrasil.com \
    --to=adam@yggdrasil.com \
    --cc=akpm@osdl.org \
    --cc=chrisw@osdl.org \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maneesh@in.ibm.com \
    --cc=viro@parcelfarce.linux.theplanet.co.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;
as well as URLs for NNTP newsgroup(s).