Skip to content

Commit 1402d17

Browse files
sherllykdave
authored andcommitted
btrfs: fix transaction leak in btrfs_recover_relocation
btrfs_recover_relocation() invokes btrfs_join_transaction(), which joins a btrfs_trans_handle object into transactions and returns a reference of it with increased refcount to "trans". When btrfs_recover_relocation() returns, "trans" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one exception handling path of btrfs_recover_relocation(). When read_fs_root() failed, the refcnt increased by btrfs_join_transaction() is not decreased, causing a refcnt leak. Fix this issue by calling btrfs_end_transaction() on this error path when read_fs_root() failed. Fixes: 79787ea ("btrfs: replace many BUG_ONs with proper error handling") CC: [email protected] # 4.4+ Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Xiyu Yang <[email protected]> Signed-off-by: Xin Tan <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f6033c5 commit 1402d17

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

fs/btrfs/relocation.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4559,6 +4559,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
45594559
if (IS_ERR(fs_root)) {
45604560
err = PTR_ERR(fs_root);
45614561
list_add_tail(&reloc_root->root_list, &reloc_roots);
4562+
btrfs_end_transaction(trans);
45624563
goto out_unset;
45634564
}
45644565

0 commit comments

Comments
 (0)