public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Colin King <colin.king@canonical.com>, Chris Mason <clm@fb.com>,
	David Sterba <dsterba@suse.com>,
	Josef Bacik <josef@toxicpanda.com>,
	linux-btrfs@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next][V3] btrfs: fix memory leak of path on error return path
Date: Fri, 5 Jul 2019 10:30:48 +0300	[thread overview]
Message-ID: <baaeb457-d592-df65-51a6-762747943dbd@suse.com> (raw)
In-Reply-To: <20190705072624.14163-1-colin.king@canonical.com>



On 5.07.19 г. 10:26 ч., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently if the allocation of roots or tmp_ulist fails the error handling
> does not free up the allocation of path causing a memory leak. Fix this and
> other similar leaks by moving the call of btrfs_free_path from label out
> to label out_free_ulist.
> 
> Kudos to David Sterba for spotting the issue in my original fix and suggesting
> the correct way to fix the leak and Anand Jain for spotting a double free
> issue.
> 
> Addresses-Coverity: ("Resource leak")
> Fixes: 5911c8fe05c5 ("btrfs: fiemap: preallocate ulists for btrfs_check_shared")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
> V2: move the btrfs_free_path to the out_free_ulist label as suggested by
>      David Sterba as the correct fix.
> V3: fix double free as identified Anand Jain
> ---
> 
>  fs/btrfs/extent_io.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 1eb671c16ff1..9de119194f8e 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -4613,7 +4613,6 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>  	ret = btrfs_lookup_file_extent(NULL, root, path,
>  			btrfs_ino(BTRFS_I(inode)), -1, 0);
>  	if (ret < 0) {
> -		btrfs_free_path(path);
>  		goto out_free_ulist;
>  	} else {
>  		WARN_ON(!ret);
> @@ -4766,11 +4765,11 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>  		ret = emit_last_fiemap_cache(fieinfo, &cache);
>  	free_extent_map(em);
>  out:
> -	btrfs_free_path(path);
>  	unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, start + len - 1,
>  			     &cached_state);
>  
>  out_free_ulist:
> +	btrfs_free_path(path);
>  	ulist_free(roots);
>  	ulist_free(tmp_ulist);
>  	return ret;
> 

      reply	other threads:[~2019-07-05  7:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-05  7:26 [PATCH][next][V3] btrfs: fix memory leak of path on error return path Colin King
2019-07-05  7:30 ` Nikolay Borisov [this message]

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=baaeb457-d592-df65-51a6-762747943dbd@suse.com \
    --to=nborisov@suse.com \
    --cc=clm@fb.com \
    --cc=colin.king@canonical.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.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