[PATCH] ramfs: Fix memory leak on ramfs_fill_super error paths

From: Axel Lin
Date: Thu Nov 14 2013 - 01:59:41 EST


The memory leak was introduced by commit 318ceed0884
"tidy up after d_make_root() conversion".

Signed-off-by: Axel Lin <axel.lin@xxxxxxxxxx>
---
fs/ramfs/inode.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index 39d1465..868a41e 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -221,7 +221,7 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent)

err = ramfs_parse_options(data, &fsi->mount_opts);
if (err)
- return err;
+ goto fail;

sb->s_maxbytes = MAX_LFS_FILESIZE;
sb->s_blocksize = PAGE_CACHE_SIZE;
@@ -232,10 +232,16 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent)

inode = ramfs_get_inode(sb, NULL, S_IFDIR | fsi->mount_opts.mode, 0);
sb->s_root = d_make_root(inode);
- if (!sb->s_root)
- return -ENOMEM;
+ if (!sb->s_root) {
+ err = -ENOMEM;
+ goto fail;
+ }

return 0;
+fail:
+ kfree(fsi);
+ sb->s_fs_info = NULL;
+ return err;
}

struct dentry *ramfs_mount(struct file_system_type *fs_type,
--
1.8.1.2



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/