diff mbox series

btrfs: tests: fix chunk map leak after failure to add it to the tree

Message ID f05862e33146ef046f6d377b8b2663b69f2c2e84.1741709026.git.fdmanana@suse.com (mailing list archive)
State New
Headers show
Series btrfs: tests: fix chunk map leak after failure to add it to the tree | expand

Commit Message

Filipe Manana March 11, 2025, 4:06 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

If we fail to add the chunk map to the fs mapping tree we exit
test_rmap_block() without freeing the chunk map. Fix this by adding a
call to btrfs_free_chunk_map() before exiting the test function if the
call to btrfs_add_chunk_map() failed.

Fixes: 7dc66abb5a47 ("btrfs: use a dedicated data structure for chunk maps")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/tests/extent-map-tests.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Boris Burkov March 11, 2025, 4:19 p.m. UTC | #1
On Tue, Mar 11, 2025 at 04:06:46PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> If we fail to add the chunk map to the fs mapping tree we exit
> test_rmap_block() without freeing the chunk map. Fix this by adding a
> call to btrfs_free_chunk_map() before exiting the test function if the
> call to btrfs_add_chunk_map() failed.
> 
> Fixes: 7dc66abb5a47 ("btrfs: use a dedicated data structure for chunk maps")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Boris Burkov <boris@bur.io>
> ---
>  fs/btrfs/tests/extent-map-tests.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/btrfs/tests/extent-map-tests.c b/fs/btrfs/tests/extent-map-tests.c
> index 56e61ac1cc64..609bb6c9c087 100644
> --- a/fs/btrfs/tests/extent-map-tests.c
> +++ b/fs/btrfs/tests/extent-map-tests.c
> @@ -1045,6 +1045,7 @@ static int test_rmap_block(struct btrfs_fs_info *fs_info,
>  	ret = btrfs_add_chunk_map(fs_info, map);
>  	if (ret) {
>  		test_err("error adding chunk map to mapping tree");
> +		btrfs_free_chunk_map(map);
>  		goto out_free;
>  	}
>  
> -- 
> 2.45.2
>
Qu Wenruo March 11, 2025, 9:25 p.m. UTC | #2
在 2025/3/12 02:36, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
> 
> If we fail to add the chunk map to the fs mapping tree we exit
> test_rmap_block() without freeing the chunk map. Fix this by adding a
> call to btrfs_free_chunk_map() before exiting the test function if the
> call to btrfs_add_chunk_map() failed.
> 
> Fixes: 7dc66abb5a47 ("btrfs: use a dedicated data structure for chunk maps")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   fs/btrfs/tests/extent-map-tests.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/fs/btrfs/tests/extent-map-tests.c b/fs/btrfs/tests/extent-map-tests.c
> index 56e61ac1cc64..609bb6c9c087 100644
> --- a/fs/btrfs/tests/extent-map-tests.c
> +++ b/fs/btrfs/tests/extent-map-tests.c
> @@ -1045,6 +1045,7 @@ static int test_rmap_block(struct btrfs_fs_info *fs_info,
>   	ret = btrfs_add_chunk_map(fs_info, map);
>   	if (ret) {
>   		test_err("error adding chunk map to mapping tree");
> +		btrfs_free_chunk_map(map);
>   		goto out_free;
>   	}
>
diff mbox series

Patch

diff --git a/fs/btrfs/tests/extent-map-tests.c b/fs/btrfs/tests/extent-map-tests.c
index 56e61ac1cc64..609bb6c9c087 100644
--- a/fs/btrfs/tests/extent-map-tests.c
+++ b/fs/btrfs/tests/extent-map-tests.c
@@ -1045,6 +1045,7 @@  static int test_rmap_block(struct btrfs_fs_info *fs_info,
 	ret = btrfs_add_chunk_map(fs_info, map);
 	if (ret) {
 		test_err("error adding chunk map to mapping tree");
+		btrfs_free_chunk_map(map);
 		goto out_free;
 	}