Skip to content

Commit

Permalink
btrfs: fix ulist leaks in error paths of qgroup self tests
Browse files Browse the repository at this point in the history
[ Upstream commit d37de92 ]

In the test_no_shared_qgroup() and test_multiple_refs() qgroup self tests,
if we fail to add the tree ref, remove the extent item or remove the
extent ref, we are returning from the test function without freeing the
"old_roots" ulist that was allocated by the previous calls to
btrfs_find_all_roots(). Fix that by calling ulist_free() before returning.

Fixes: 442244c ("btrfs: qgroup: Switch self test to extent-oriented qgroup mechanism.")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
fdmanana authored and gregkh committed Nov 10, 2022
1 parent 222a3d5 commit f46ea5f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions fs/btrfs/tests/qgroup-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ static int test_no_shared_qgroup(struct btrfs_root *root,

ret = insert_normal_tree_ref(root, nodesize, nodesize, 0,
BTRFS_FS_TREE_OBJECTID);
if (ret)
if (ret) {
ulist_free(old_roots);
return ret;
}

ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
if (ret) {
Expand Down Expand Up @@ -266,8 +268,10 @@ static int test_no_shared_qgroup(struct btrfs_root *root,
}

ret = remove_extent_item(root, nodesize, nodesize);
if (ret)
if (ret) {
ulist_free(old_roots);
return -EINVAL;
}

ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
if (ret) {
Expand Down Expand Up @@ -329,8 +333,10 @@ static int test_multiple_refs(struct btrfs_root *root,

ret = insert_normal_tree_ref(root, nodesize, nodesize, 0,
BTRFS_FS_TREE_OBJECTID);
if (ret)
if (ret) {
ulist_free(old_roots);
return ret;
}

ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
if (ret) {
Expand Down Expand Up @@ -362,8 +368,10 @@ static int test_multiple_refs(struct btrfs_root *root,

ret = add_tree_ref(root, nodesize, nodesize, 0,
BTRFS_FIRST_FREE_OBJECTID);
if (ret)
if (ret) {
ulist_free(old_roots);
return ret;
}

ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
if (ret) {
Expand Down Expand Up @@ -401,8 +409,10 @@ static int test_multiple_refs(struct btrfs_root *root,

ret = remove_extent_ref(root, nodesize, nodesize, 0,
BTRFS_FIRST_FREE_OBJECTID);
if (ret)
if (ret) {
ulist_free(old_roots);
return ret;
}

ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
if (ret) {
Expand Down

0 comments on commit f46ea5f

Please sign in to comment.