]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: fix leaf leak in an error path in btrfs_del_items()
authorFilipe Manana <fdmanana@suse.com>
Thu, 13 Nov 2025 12:52:45 +0000 (12:52 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:42:24 +0000 (22:42 +0100)
If the call to btrfs_del_leaf() fails we return without decrementing the
extra ref we took on the leaf, therefore leaking it. Fix this by ensuring
we drop the ref count before returning the error.

Fixes: 751a27615dda ("btrfs: do not BUG_ON() on tree mod log failures at btrfs_del_ptr()")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.c

index f6a9b6bbf78bd19ec905ee98cdb8d4a86daa64ec..614aa4b56571ba00b71f4de785f8ac0bf0790ea8 100644 (file)
@@ -4562,9 +4562,9 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                        if (btrfs_header_nritems(leaf) == 0) {
                                path->slots[1] = slot;
                                ret = btrfs_del_leaf(trans, root, path, leaf);
+                               free_extent_buffer(leaf);
                                if (ret < 0)
                                        return ret;
-                               free_extent_buffer(leaf);
                                ret = 0;
                        } else {
                                /* if we're still in the path, make sure