mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 4/5] fs: efs: fix possible memory leak
Date: Thu, 12 Feb 2015 14:32:21 +0530	[thread overview]
Message-ID: <1423731742-31383-4-git-send-email-sudipm.mukherjee@gmail.com> (raw)
In-Reply-To: <1423731742-31383-1-git-send-email-sudipm.mukherjee@gmail.com>

we are allocating memory for struct efs_sb_info, but afterwards when
we are returning with error we are not releasing the memory.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
 fs/efs/super.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/fs/efs/super.c b/fs/efs/super.c
index 6026bd4..e1037aa 100644
--- a/fs/efs/super.c
+++ b/fs/efs/super.c
@@ -233,6 +233,7 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
 	struct efs_sb_info *sb;
 	struct buffer_head *bh;
 	struct inode *root;
+	int ret = -EINVAL;
 
 	sb = kzalloc(sizeof(struct efs_sb_info), GFP_KERNEL);
 	if (!sb)
@@ -243,7 +244,7 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
 	if (!sb_set_blocksize(s, EFS_BLOCKSIZE)) {
 		pr_err("device does not support %d byte blocks\n",
 			EFS_BLOCKSIZE);
-		return -EINVAL;
+		goto err_out;
 	}
 
 	/* read the vh (volume header) block */
@@ -251,7 +252,7 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
 
 	if (!bh) {
 		pr_err("cannot read volume header\n");
-		return -EINVAL;
+		goto err_out;
 	}
 
 	/*
@@ -262,14 +263,13 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
 	sb->fs_start = efs_validate_vh((struct volume_header *) bh->b_data);
 	brelse(bh);
 
-	if (sb->fs_start == -1) {
-		return -EINVAL;
-	}
+	if (sb->fs_start == -1)
+		goto err_out;
 
 	bh = sb_bread(s, sb->fs_start + EFS_SUPER);
 	if (!bh) {
 		pr_err("cannot read superblock\n");
-		return -EINVAL;
+		goto err_out;
 	}
 
 	if (efs_validate_super(sb, (struct efs_super *) bh->b_data)) {
@@ -278,7 +278,7 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
 			sb->fs_start + EFS_SUPER);
 #endif
 		brelse(bh);
-		return -EINVAL;
+		goto err_out;
 	}
 	brelse(bh);
 
@@ -293,16 +293,22 @@ static int efs_fill_super(struct super_block *s, void *d, int silent)
 	root = efs_iget(s, EFS_ROOTINODE);
 	if (IS_ERR(root)) {
 		pr_err("get root inode failed\n");
-		return PTR_ERR(root);
+		ret = PTR_ERR(root);
+		goto err_out;
 	}
 
 	s->s_root = d_make_root(root);
 	if (!(s->s_root)) {
 		pr_err("get root dentry failed\n");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto err_out;
 	}
 
 	return 0;
+
+err_out:
+	kfree(sb);
+	return ret;
 }
 
 static struct dentry *efs_mount(struct file_system_type *fs_type,
-- 
1.8.1.2


  parent reply	other threads:[~2015-02-12  9:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-12  9:02 [PATCH 1/5] fs: efs: fix trailing and leading space Sudip Mukherjee
2015-02-12  9:02 ` [PATCH 2/5] fs: efs: fix forward declarations Sudip Mukherjee
2015-02-12  9:02 ` [PATCH 3/5] fs: efs: remove nonexistant site Sudip Mukherjee
2015-02-12  9:02 ` Sudip Mukherjee [this message]
2015-02-17 19:31   ` [PATCH 4/5] fs: efs: fix possible memory leak Al Viro
2015-02-18 13:56     ` Sudip Mukherjee
2015-02-12  9:02 ` [PATCH 5/5] MAINTAINERS: remove website Sudip Mukherjee

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=1423731742-31383-4-git-send-email-sudipm.mukherjee@gmail.com \
    --to=sudipm.mukherjee@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®