public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Axel Lin <axel.lin@ingics.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>, Rob Landley <rob@landley.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ramfs: Fix memory leak on ramfs_fill_super error paths
Date: Thu, 14 Nov 2013 12:19:48 +0200	[thread overview]
Message-ID: <20131114101948.GA12195@shutemov.name> (raw)
In-Reply-To: <1384412359.28992.3.camel@phoenix>

On Thu, Nov 14, 2013 at 02:59:19PM +0800, Axel Lin wrote:
> The memory leak was introduced by commit 318ceed0884
> "tidy up after d_make_root() conversion".
> 
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  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;

Why do we need this?
mount_nodev() seems just drop super block if filler fails.

> +	return err;
>  }
>  
>  struct dentry *ramfs_mount(struct file_system_type *fs_type,
-- 
 Kirill A. Shutemov

  reply	other threads:[~2013-11-14 11:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-14  6:59 [PATCH] ramfs: Fix memory leak on ramfs_fill_super error paths Axel Lin
2013-11-14 10:19 ` Kirill A. Shutemov [this message]
2013-11-14 14:10 ` Al Viro

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=20131114101948.GA12195@shutemov.name \
    --to=kirill@shutemov.name \
    --cc=akpm@linux-foundation.org \
    --cc=axel.lin@ingics.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob@landley.net \
    --cc=viro@zeniv.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