Skip to content

Commit e87e953

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]> Signed-off-by: David Sterba <[email protected]>
1 parent 2b39796 commit e87e953

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
@@ -6854,6 +6854,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
68546854
ret = btrfs_update_inode(trans, BTRFS_I(inode));
68556855
if (ret) {
68566856
btrfs_abort_transaction(trans, ret);
6857+
drop_inode = 1;
68576858
goto fail;
68586859
}
68596860
if (inode->i_nlink == 1) {
@@ -6864,6 +6865,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
68646865
ret = btrfs_orphan_del(trans, BTRFS_I(inode));
68656866
if (ret) {
68666867
btrfs_abort_transaction(trans, ret);
6868+
drop_inode = 1;
68676869
goto fail;
68686870
}
68696871
}

0 commit comments

Comments
 (0)