linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Colin Ian King <colin.king@canonical.com>
Cc: dsterba@suse.cz, Chris Mason <clm@fb.com>,
	Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] btrfs: fix memory leak of path on error return path
Date: Thu, 4 Jul 2019 19:20:07 +0200	[thread overview]
Message-ID: <20190704172007.GB20977@twin.jikos.cz> (raw)
In-Reply-To: <366d87f9-96ea-ecc3-6464-9d20e3050248@canonical.com>

On Thu, Jul 04, 2019 at 05:47:50PM +0100, Colin Ian King wrote:
> >>  	tmp_ulist = ulist_alloc(GFP_KERNEL);
> >>  	if (!roots || !tmp_ulist) {
> >>  		ret = -ENOMEM;
> >> +		btrfs_free_path(path);
> > 
> > This fixes only one leak, therere are more that I spotted while
> > reviewing this patch. The gotos from the while-loop jump to
> > out_free_list but that leave the path behind>
> > That's why the exit block is a better place for the cleanups. This
> > requires proper nesting of the cleanup calls, that's slightly
> > inconvenient in this case. The free_path is before call to
> > unlock_extent_cached so when the ordre is switched and free_path moved
> > to out_free_ulist, then all the leaks are addressed in one go.
> 
> Oh, yes. Even static analysis missed that too!
> 
> > Bummer that the leaks escaped sight of original patch author (me), 2
> > reviewers and now 1 fix reviewer.
> > 
> Given that you can see more issues, I'll leave the fix in your capable
> hands.

This

--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4764,11 +4764,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;
---

should fix it.

  reply	other threads:[~2019-07-04 17:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-02 14:10 [PATCH][next] btrfs: fix memory leak of path on error return path Colin King
2019-07-04 16:37 ` David Sterba
2019-07-04 16:47   ` Colin Ian King
2019-07-04 17:20     ` David Sterba [this message]
2019-07-05  1:28   ` Anand Jain

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=20190704172007.GB20977@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --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;
as well as URLs for NNTP newsgroup(s).