]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: ref-verify: fix memory leak in add_block_entry
authorTom Rix <trix@redhat.com>
Tue, 7 Jul 2020 13:29:08 +0000 (06:29 -0700)
committerDavid Sterba <dsterba@suse.com>
Mon, 27 Jul 2020 10:55:43 +0000 (12:55 +0200)
commit0251cd9e4dc96e9811494c6aebf1e76d1d2971a1
tree7070eb8e92ebde69efcc9a3b2df2bd85c554ac88
parentbe3d67706eaca52f7b6448e87154edd6d25feec6
btrfs: ref-verify: fix memory leak in add_block_entry

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: 24471c3fac5a ("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>
fs/btrfs/ref-verify.c