summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZilin Guan <zilin@seu.edu.cn>2025-12-26 11:30:22 +0000
committerDavid Sterba <dsterba@suse.com>2026-01-09 17:41:45 +0100
commitbe1c2e8afe3ac4a4f15a13f6844619c2cf47b1d1 (patch)
tree2ee9d8e06cad863cd7221899d64a4cd354ddc365
parent1e1f2055ad5a7a5d548789b334a4473a7665c418 (diff)
downloadlwn-be1c2e8afe3ac4a4f15a13f6844619c2cf47b1d1.tar.gz
lwn-be1c2e8afe3ac4a4f15a13f6844619c2cf47b1d1.zip
btrfs: tests: fix root tree leak in btrfs_test_qgroups()
If btrfs_insert_fs_root() fails, the tmp_root allocated by btrfs_alloc_dummy_root() is leaked because its initial reference count is not decremented. Fix this by calling btrfs_put_root() unconditionally after btrfs_insert_fs_root(). This ensures the local reference is always dropped. Also fix a copy-paste error in the error message where the subvolume root insertion failure was incorrectly logged as "fs root". Co-developed-by: Jianhao Xu <jianhao.xu@seu.edu.cn> Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn> Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/tests/qgroup-tests.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c
index e9124605974b..0fcc31beeffe 100644
--- a/fs/btrfs/tests/qgroup-tests.c
+++ b/fs/btrfs/tests/qgroup-tests.c
@@ -517,11 +517,11 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
tmp_root->root_key.objectid = BTRFS_FS_TREE_OBJECTID;
root->fs_info->fs_root = tmp_root;
ret = btrfs_insert_fs_root(root->fs_info, tmp_root);
+ btrfs_put_root(tmp_root);
if (ret) {
test_err("couldn't insert fs root %d", ret);
goto out;
}
- btrfs_put_root(tmp_root);
tmp_root = btrfs_alloc_dummy_root(fs_info);
if (IS_ERR(tmp_root)) {
@@ -532,11 +532,11 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
tmp_root->root_key.objectid = BTRFS_FIRST_FREE_OBJECTID;
ret = btrfs_insert_fs_root(root->fs_info, tmp_root);
+ btrfs_put_root(tmp_root);
if (ret) {
- test_err("couldn't insert fs root %d", ret);
+ test_err("couldn't insert subvolume root %d", ret);
goto out;
}
- btrfs_put_root(tmp_root);
test_msg("running qgroup tests");
ret = test_no_shared_qgroup(root, sectorsize, nodesize);