btrfs: fix extent map leak in unexpected scenario at unpin_extent_cache()
authorFilipe Manana <fdmanana@suse.com>
Wed, 13 Mar 2024 11:37:31 +0000 (11:37 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 26 Mar 2024 15:42:38 +0000 (16:42 +0100)
commit8a565ec04d6c43f330e7401e5af3458431b29bc6
tree68cb88d5775a2fe58fac733df0c425fa877c12f7
parent9f7eb8405dcbc79c5434821e9e3e92abe187ee8e
btrfs: fix extent map leak in unexpected scenario at unpin_extent_cache()

At unpin_extent_cache() if we happen to find an extent map with an
unexpected start offset, we jump to the 'out' label and never release the
reference we added to the extent map through the call to
lookup_extent_mapping(), therefore resulting in a leak. So fix this by
moving the free_extent_map() under the 'out' label.

Fixes: c03c89f821e5 ("btrfs: handle errors returned from unpin_extent_cache()")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_map.c