]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: release root after error in data_reloc_print_warning_inode()
authorZilin Guan <zilin@seu.edu.cn>
Wed, 5 Nov 2025 02:37:22 +0000 (02:37 +0000)
committerDavid Sterba <dsterba@suse.com>
Wed, 5 Nov 2025 19:01:12 +0000 (20:01 +0100)
data_reloc_print_warning_inode() calls btrfs_get_fs_root() to obtain
local_root, but fails to release its reference when paths_from_inode()
returns an error. This causes a potential memory leak.

Add a missing btrfs_put_root() call in the error path to properly
decrease the reference count of local_root.

Fixes: b9a9a85059cde ("btrfs: output affected files when relocation fails")
CC: stable@vger.kernel.org # 6.6+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index b95175116ea3ec6868448bf7bb0c682e41ab511a..d097532fd85b424d2553e14e6dfea3ad8cab2f5c 100644 (file)
@@ -177,8 +177,10 @@ static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
                return ret;
        }
        ret = paths_from_inode(inum, ipath);
-       if (ret < 0)
+       if (ret < 0) {
+               btrfs_put_root(local_root);
                goto err;
+       }
 
        /*
         * We deliberately ignore the bit ipath might have been too small to