]> git.hungrycats.org Git - linux/commitdiff
Btrfs: fix transaction handle leak on failure to create hard link
authorFilipe Manana <fdmanana@suse.com>
Tue, 5 Jan 2016 16:24:05 +0000 (16:24 +0000)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Tue, 19 Jan 2016 05:23:50 +0000 (00:23 -0500)
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 <fdmanana@suse.com>
(cherry picked from commit ca003b4cbeb0149b9814d86589ec61072bd7c16d)
(cherry picked from commit 7540a6c8692696d1e9f7c6245a6914e0cc66cd18)

fs/btrfs/inode.c

index 645c5749b7eca63b29648ec08e1f88f81ccf2a80..4e38071285b3d12743863113fa1a19bc66bd1339 100644 (file)
@@ -6414,7 +6414,7 @@ out_unlock_inode:
 static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
                      struct dentry *dentry)
 {
-       struct btrfs_trans_handle *trans;
+       struct btrfs_trans_handle *trans = NULL;
        struct btrfs_root *root = BTRFS_I(dir)->root;
        struct inode *inode = d_inode(old_dentry);
        u64 index;
@@ -6440,6 +6440,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
        trans = btrfs_start_transaction(root, 5);
        if (IS_ERR(trans)) {
                err = PTR_ERR(trans);
+               trans = NULL;
                goto fail;
        }
 
@@ -6473,9 +6474,10 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
                btrfs_log_new_name(trans, inode, NULL, parent);
        }
 
-       btrfs_end_transaction(trans, root);
        btrfs_balance_delayed_items(root);
 fail:
+       if (trans)
+               btrfs_end_transaction(trans, root);
        if (drop_inode) {
                inode_dec_link_count(inode);
                iput(inode);