[PATCH 2.6.10-rc2-bk15] sysfs_dir_close memory leak

From: Adam J. Richter (adam_at_yggdrasil.com)
Date: 12/03/04

  • Next message: john stultz: "Re: do_posix_clock_monotonic_gettime() returns negative nsec"
    Date:	Thu, 2 Dec 2004 18:50:35 -0800
    To: maneesh@in.ibm.com
    
    

            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;
     }
     
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: john stultz: "Re: do_posix_clock_monotonic_gettime() returns negative nsec"

    Relevant Pages

    • [GIT PATCH 04/18] mousedev: fix memory leak
      ... +static void mixdev_release ... static int mousedev_release(struct inode * inode, struct file * file) ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • sr.c kobject refcounting got buggered [Re: Ooops unmounting a defect DVD]
      ... static int sr_block_release(struct inode *inode, struct file *file) ... static void sr_kref_release(struct kref *kref) ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: 2.6.13-rc4 use after free in class_device_attr_show
      ... static int sysfs_open_file(struct inode * inode, struct file * filp) ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [PATCH] [1/2] random: SMP locking
      ... random_ioctl(struct inode * inode, struct file * file, ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ...
      (Linux-Kernel)
    • Re: Pollable Semaphores
      ... >> hoping that we get support for this, perhaps in the form of polling ... static int mem_open(struct inode* inode, struct file* file) ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)