• Tom Rix's avatar
    btrfs: ref-verify: fix memory leak in add_block_entry · d60ba8de
    Tom Rix authored
    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: fd708b81 ("Btrfs: add a extent ref verify tool")
    CC: stable@vger.kernel.org # 4.19+
    Signed-off-by: default avatarTom Rix <trix@redhat.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    d60ba8de
ref-verify.c 25.3 KB