lkml.org 
[lkml]   [2020]   [Aug]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.8 017/232] btrfs: ref-verify: fix memory leak in add_block_entry
    Date
    From: Tom Rix <trix@redhat.com>

    commit d60ba8de1164e1b42e296ff270c622a070ef8fe7 upstream.

    clang static analysis flags this error

    fs/btrfs/ref-verify.c:290:3: warning: Potential leak of memory pointed to by 're' [unix.Malloc]
    kfree(be);
    ^~~~~

    The problem is in this block of code:

    if (root_objectid) {
    struct root_entry *exist_re;

    exist_re = insert_root_entry(&exist->roots, re);
    if (exist_re)
    kfree(re);
    }

    There is no 'else' block freeing when root_objectid is 0. Add the
    missing kfree to the else branch.

    Fixes: fd708b81d972 ("Btrfs: add a extent ref verify tool")
    CC: stable@vger.kernel.org # 4.19+
    Signed-off-by: Tom Rix <trix@redhat.com>
    Reviewed-by: David Sterba <dsterba@suse.com>
    Signed-off-by: David Sterba <dsterba@suse.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    fs/btrfs/ref-verify.c | 2 ++
    1 file changed, 2 insertions(+)

    --- a/fs/btrfs/ref-verify.c
    +++ b/fs/btrfs/ref-verify.c
    @@ -286,6 +286,8 @@ static struct block_entry *add_block_ent
    exist_re = insert_root_entry(&exist->roots, re);
    if (exist_re)
    kfree(re);
    + } else {
    + kfree(re);
    }
    kfree(be);
    return exist;

    \
     
     \ /
      Last update: 2020-08-20 16:07    [W:4.185 / U:0.080 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site