linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: Shilong Wang <wangshilong1991@gmail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 14/17] btrfs-progs: fix mem leak in resolve_root
Date: Mon, 25 Feb 2013 22:36:41 -0600	[thread overview]
Message-ID: <512C3BD9.6000008@redhat.com> (raw)
In-Reply-To: <CAP9B-QkUP7ZftFkWw-_W-K2YKT8KdymabTf2mEK8Z_mgiKaJnA@mail.gmail.com>

On 2/25/13 6:36 PM, Shilong Wang wrote:
> Hello, Eric
> 
> 2013/2/26 Eric Sandeen <sandeen@redhat.com>:
>> If we exit with error we must free the allocated memory
>> to avoid a leak.
>>
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
>> ---
>>  btrfs-list.c |    8 ++++++--
>>  1 files changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/btrfs-list.c b/btrfs-list.c
>> index 851c059..8c3f84d 100644
>> --- a/btrfs-list.c
>> +++ b/btrfs-list.c
>> @@ -568,8 +568,10 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
>>                 * ref_tree = 0 indicates the subvolumes
>>                 * has been deleted.
>>                 */
>> -               if (!found->ref_tree)
>> +               if (!found->ref_tree) {
>> +                       free(full_path);
>>                         return -ENOENT;
>> +               }
>>                 int add_len = strlen(found->path);
>>
>>                 /* room for / and for null */
>> @@ -612,8 +614,10 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
>>                 * subvolume was deleted.
>>                 */
>>                 found = root_tree_search(rl, next);
>> -               if (!found)
>> +               if (!found) {
>> +                       free(full_path);
>>                         return -ENOENT;
>> +               }
>>         }
>>
>>         ri->full_path = full_path;
>> --
>> 1.7.1
> 
> I think the patch is wrong;
> Here we return ENOENT, it means a subvolume/snapshot deletion happens.
> We just filter them in the filter_root, But the free work is done by
> the function all_subvolume_free..
> so your modification will cause a double free..

Thanks for the review.  I'll admit that when looking at too many of
these static checker reports, sometimes things look obvious when
they are actually subtle, and I've certainly made mistakes before. :)

However, full_path location doesn't seem to be available outside the
scope of this function unless we exit normally and do:

        ri->full_path = full_path;

        return 0;
}

If we exit early at the -ENOENT points, it seems that full_path
is leaked; there are no other references to it.
Am I missing something?

Thanks,
-Eric

> Thanks,
> Wang
> 
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html


  reply	other threads:[~2013-02-26  4:36 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-25 22:54 [PATCH 00/17] btrfs-progs: More misc fixes & cleanups Eric Sandeen
2013-02-25 22:54 ` [PATCH 01/17] btrfs-progs: Unify size-parsing Eric Sandeen
2013-02-25 23:26   ` Zach Brown
2013-02-25 23:37     ` Eric Sandeen
2013-02-26  0:26       ` Zach Brown
2013-02-26 18:50   ` Goffredo Baroncelli
2013-02-26 20:17     ` Eric Sandeen
2013-02-26 21:15       ` Goffredo Baroncelli
2013-02-25 22:54 ` [PATCH 02/17] btrfs-progs: fix btrfs_get_subvol cut/paste error Eric Sandeen
2013-02-25 22:54 ` [PATCH 03/17] btrfs-progs: Remove write-only var fdres in cmd_dev_stats() Eric Sandeen
2013-02-25 22:54 ` [PATCH 04/17] btrfs-progs: btrfs_list_get_path_rootid error handling Eric Sandeen
2013-02-25 22:54 ` [PATCH 05/17] btrfs-progs: avoid double-free in __btrfs_map_block Eric Sandeen
2013-02-25 22:54 ` [PATCH 06/17] btrfs-progs: fix open error test in cmd_start_replace Eric Sandeen
2013-02-25 22:54 ` [PATCH 07/17] btrfs-progs: fix close of error fd in scrub cancel Eric Sandeen
2013-02-25 22:54 ` [PATCH 08/17] btrfs-progs: more scrub cancel error handling Eric Sandeen
2013-02-25 22:54 ` [PATCH 09/17] btrfs-progs: free memory before error exit in read_whole_eb Eric Sandeen
2013-02-25 22:54 ` [PATCH 10/17] btrfs-progs: don't call close on error fd Eric Sandeen
2013-02-25 22:54 ` [PATCH 11/17] btrfs-progs: provide positive errno to strerror in cmd_restore Eric Sandeen
2013-02-25 22:54 ` [PATCH 12/17] btrfs-progs: free allocated di_args in cmd_start_replace Eric Sandeen
2013-02-25 22:54 ` [PATCH 13/17] btrfs-progs: close fd on cmd_subvol_get_default return Eric Sandeen
2013-02-25 22:54 ` [PATCH 14/17] btrfs-progs: fix mem leak in resolve_root Eric Sandeen
2013-02-26  0:36   ` Shilong Wang
2013-02-26  4:36     ` Eric Sandeen [this message]
2013-02-27 13:03       ` David Sterba
2013-02-27 13:12         ` Shilong Wang
2013-02-25 22:54 ` [PATCH 15/17] btrfs-progs: Tidy up resolve_root Eric Sandeen
2013-02-25 22:54 ` [PATCH 16/17] btrfs-progs: fix fd leak in cmd_subvol_set_default Eric Sandeen
2013-02-26 18:46   ` Goffredo Baroncelli
2013-02-26 20:10     ` Eric Sandeen
2013-02-26 21:04       ` Goffredo Baroncelli
2013-02-27 12:38         ` David Sterba
2013-02-25 22:54 ` [PATCH 17/17] btrfs-progs: replace strtok_r with strsep Eric Sandeen
2013-02-26 18:47   ` Goffredo Baroncelli
2013-02-26 20:13     ` Eric Sandeen
2013-02-26 20:20     ` [PATCH 17/17 V2] " Eric Sandeen
2013-02-26 20:40       ` Ilya Dryomov
2013-02-26 20:46         ` Eric Sandeen
2013-02-26 21:07           ` Ilya Dryomov
2013-02-26 21:50             ` [PATCH 17/17 V3] btrfs-progs: initialize save_ptr prior to strtok_r Eric Sandeen
2013-02-27 13:54 ` [PATCH 00/17] btrfs-progs: More misc fixes & cleanups David Sterba

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=512C3BD9.6000008@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wangshilong1991@gmail.com \
    /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).