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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Aug 2020 11:07:19 +0000 (13:07 +0200)
commit70fb164d5263b62f7cb2b13ab75ba90bd8b5f5ff
treeef61c57cb77a8ebac7ccf42be14113a9f2b53879
parent54e9870d75df4816ad8cee677d8e4fd116cad040
btrfs: ref-verify: fix memory leak in add_block_entry

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