[PATCH] btrfs: Fix root reference leak in merge_reloc_roots()
From: Wentao Liang
Date: Wed Sep 16 2026 - 13:28:47 EST
When the fs root read back for a reloc root does not have the expected
reloc_root backref, merge_reloc_roots() warns, sets ret = -EINVAL and
jumps to out without dropping the reference returned by
btrfs_get_fs_root(), leaking it on this error path.
Drop the reference before jumping to out, matching what
merge_reloc_root() already does for the same mismatch condition.
Fixes: 05d7ce504545 ("btrfs: exit gracefully if reloc roots don't match")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
fs/btrfs/relocation.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 3ebaf5880125..6c826be41749 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1850,6 +1850,7 @@ void merge_reloc_roots(struct reloc_control *rc)
* corruption, e.g. bad reloc tree key offset.
*/
ret = -EINVAL;
+ btrfs_put_root(root);
goto out;
}
ret = merge_reloc_root(rc, root);
--
2.34.1