]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: fix inode leak on failure to add link to inode
authorFilipe Manana <fdmanana@suse.com>
Fri, 25 Jul 2025 15:54:49 +0000 (16:54 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 21 Aug 2025 22:58:27 +0000 (00:58 +0200)
If we fail to update the inode or delete the orphan item we leak the inode
since we update its refcount with the ihold() call to account for the
d_instantiate() call which never happens in case we fail those steps. Fix
this by setting 'drop_inode' to true in case we fail those steps.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index af2f9b2c8c851c1b6cf695c876fa1271052cc7cf..4ed5ab5d3ac15bccbcb2aba463f5529d93a9ee0c 100644 (file)
@@ -6854,6 +6854,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
                ret = btrfs_update_inode(trans, BTRFS_I(inode));
                if (ret) {
                        btrfs_abort_transaction(trans, ret);
+                       drop_inode = 1;
                        goto fail;
                }
                if (inode->i_nlink == 1) {
@@ -6864,6 +6865,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
                        ret = btrfs_orphan_del(trans, BTRFS_I(inode));
                        if (ret) {
                                btrfs_abort_transaction(trans, ret);
+                               drop_inode = 1;
                                goto fail;
                        }
                }