* [PATCH v2] btrfs: tests: Fix memory leak in btrfs_test_qgroups()
@ 2025-12-26 11:30 Zilin Guan
2026-01-06 12:38 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Zilin Guan @ 2025-12-26 11:30 UTC (permalink / raw)
To: clm
Cc: dsterba, sunk67188, dan.carpenter, linux-btrfs, linux-kernel,
jianhao.xu, Zilin Guan
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>
---
Changes in v2:
- Reword commit message to be more concise.
- Fix copy-paste error in the error message.
- Add Co-developed-by and Signed-off-by tag.
---
fs/btrfs/tests/qgroup-tests.c | 6 +++---
1 file 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);
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] btrfs: tests: Fix memory leak in btrfs_test_qgroups()
2025-12-26 11:30 [PATCH v2] btrfs: tests: Fix memory leak in btrfs_test_qgroups() Zilin Guan
@ 2026-01-06 12:38 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2026-01-06 12:38 UTC (permalink / raw)
To: Zilin Guan
Cc: clm, dsterba, sunk67188, dan.carpenter, linux-btrfs,
linux-kernel, jianhao.xu
On Fri, Dec 26, 2025 at 11:30:22AM +0000, Zilin Guan wrote:
> 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>
> ---
> Changes in v2:
> - Reword commit message to be more concise.
> - Fix copy-paste error in the error message.
> - Add Co-developed-by and Signed-off-by tag.
Added to for-next, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-06 12:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-26 11:30 [PATCH v2] btrfs: tests: Fix memory leak in btrfs_test_qgroups() Zilin Guan
2026-01-06 12:38 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®