Skip to content

Commit be1c2e8

Browse files
GoodLuck612kdave
authored andcommitted
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>
1 parent 1e1f205 commit be1c2e8

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

fs/btrfs/tests/qgroup-tests.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
517517
tmp_root->root_key.objectid = BTRFS_FS_TREE_OBJECTID;
518518
root->fs_info->fs_root = tmp_root;
519519
ret = btrfs_insert_fs_root(root->fs_info, tmp_root);
520+
btrfs_put_root(tmp_root);
520521
if (ret) {
521522
test_err("couldn't insert fs root %d", ret);
522523
goto out;
523524
}
524-
btrfs_put_root(tmp_root);
525525

526526
tmp_root = btrfs_alloc_dummy_root(fs_info);
527527
if (IS_ERR(tmp_root)) {
@@ -532,11 +532,11 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
532532

533533
tmp_root->root_key.objectid = BTRFS_FIRST_FREE_OBJECTID;
534534
ret = btrfs_insert_fs_root(root->fs_info, tmp_root);
535+
btrfs_put_root(tmp_root);
535536
if (ret) {
536-
test_err("couldn't insert fs root %d", ret);
537+
test_err("couldn't insert subvolume root %d", ret);
537538
goto out;
538539
}
539-
btrfs_put_root(tmp_root);
540540

541541
test_msg("running qgroup tests");
542542
ret = test_no_shared_qgroup(root, sectorsize, nodesize);

0 commit comments

Comments
 (0)