Skip to content

Commit 6bf983c

Browse files
Tom Rixgregkh
authored andcommitted
btrfs: ref-verify: fix memory leak in add_block_entry
commit d60ba8d 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: fd708b8 ("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>
1 parent 8eadf67 commit 6bf983c

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

fs/btrfs/ref-verify.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ static struct block_entry *add_block_entry(struct btrfs_fs_info *fs_info,
297297
exist_re = insert_root_entry(&exist->roots, re);
298298
if (exist_re)
299299
kfree(re);
300+
} else {
301+
kfree(re);
300302
}
301303
kfree(be);
302304
return exist;

0 commit comments

Comments
 (0)