Skip to content

Commit 14e1aee

Browse files
fdmananakdave
authored andcommitted
btrfs: fix inode leak on failure to add link to inode
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 <[email protected]> Signed-off-by: Filipe Manana <[email protected]>
1 parent 47f1e50 commit 14e1aee

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/btrfs/inode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6848,6 +6848,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
68486848
ret = btrfs_update_inode(trans, BTRFS_I(inode));
68496849
if (ret) {
68506850
btrfs_abort_transaction(trans, ret);
6851+
drop_inode = 1;
68516852
goto fail;
68526853
}
68536854
if (inode->i_nlink == 1) {
@@ -6858,6 +6859,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
68586859
ret = btrfs_orphan_del(trans, BTRFS_I(inode));
68596860
if (ret) {
68606861
btrfs_abort_transaction(trans, ret);
6862+
drop_inode = 1;
68616863
goto fail;
68626864
}
68636865
}

0 commit comments

Comments
 (0)