Skip to content

Commit 271dba4

Browse files
committed
Btrfs: fix transaction handle leak on failure to create hard link
If we failed to create a hard link we were not always releasing the the transaction handle we got before, resulting in a memory leak and preventing any other tasks from being able to commit the current transaction. Fix this by always releasing our transaction handle. Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: Liu Bo <[email protected]>
1 parent 9269d12 commit 271dba4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/btrfs/inode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6488,7 +6488,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
64886488
static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
64896489
struct dentry *dentry)
64906490
{
6491-
struct btrfs_trans_handle *trans;
6491+
struct btrfs_trans_handle *trans = NULL;
64926492
struct btrfs_root *root = BTRFS_I(dir)->root;
64936493
struct inode *inode = d_inode(old_dentry);
64946494
u64 index;
@@ -6514,6 +6514,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
65146514
trans = btrfs_start_transaction(root, 5);
65156515
if (IS_ERR(trans)) {
65166516
err = PTR_ERR(trans);
6517+
trans = NULL;
65176518
goto fail;
65186519
}
65196520

@@ -6547,9 +6548,10 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
65476548
btrfs_log_new_name(trans, inode, NULL, parent);
65486549
}
65496550

6550-
btrfs_end_transaction(trans, root);
65516551
btrfs_balance_delayed_items(root);
65526552
fail:
6553+
if (trans)
6554+
btrfs_end_transaction(trans, root);
65536555
if (drop_inode) {
65546556
inode_dec_link_count(inode);
65556557
iput(inode);

0 commit comments

Comments
 (0)