From: Filipe David Borba Manana Date: Mon, 7 Oct 2013 11:04:28 +0000 (+0100) Subject: Btrfs: fix memory leaks on transaction commit failure X-Git-Tag: v4.9.8~7274^2~99 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=80d94fb3df2bf24a500f13181921736fa23b6c3d;p=platform%2Fkernel%2Flinux-rpi3.git Btrfs: fix memory leaks on transaction commit failure Structures of the types tree_mod_elem and qgroup_update are allocated during transaction commit but were not being released if the call to btrfs_run_delayed_items() returned an error. Stack trace reported by kmemleak: unreferenced object 0xffff880679f0b398 (size 128): comm "umount", pid 21508, jiffies 4295967793 (age 36718.112s) hex dump (first 32 bytes): 60 b5 f0 79 06 88 ff ff 00 00 00 00 00 00 00 00 `..y............ 00 00 00 00 00 00 00 00 50 1c 00 00 00 00 00 00 ........P....... backtrace: [] kmemleak_alloc+0x26/0x50 [] kmem_cache_alloc_trace+0x112/0x200 [] tree_mod_log_insert_key.constprop.45+0x93/0x150 [btrfs] [] __btrfs_cow_block+0x299/0x4f0 [btrfs] [] btrfs_cow_block+0x120/0x1f0 [btrfs] [] btrfs_search_slot+0x449/0x930 [btrfs] [] btrfs_lookup_inode+0x2f/0xa0 [btrfs] [] __btrfs_update_delayed_inode+0x1c/0x1d0 [btrfs] [] __btrfs_run_delayed_items+0x162/0x1e0 [btrfs] [] btrfs_delayed_inode_exit+0x3/0x20 [btrfs] [] btrfs_commit_transaction+0x203/0xa50 [btrfs] [] btrfs_sync_fs+0x69/0x110 [btrfs] [] __sync_filesystem+0x30/0x60 [] sync_filesystem+0x4b/0x70 [] generic_shutdown_super+0x3b/0xf0 [] kill_anon_super+0x16/0x30 unreferenced object 0xffff880677e0dd88 (size 32): comm "umount", pid 21508, jiffies 4295967793 (age 36718.112s) hex dump (first 32 bytes): 78 75 11 a9 06 88 ff ff 00 c0 e0 77 06 88 ff ff xu.........w.... 40 c3 a2 70 06 88 ff ff 00 00 00 00 00 00 00 00 @..p............ backtrace: [] kmemleak_alloc+0x26/0x50 [] kmem_cache_alloc_trace+0x112/0x200 [] btrfs_qgroup_record_ref+0xf/0x90 [btrfs] [] btrfs_add_delayed_tree_ref+0xf4/0x170 [btrfs] [] btrfs_free_tree_block+0x9a/0x220 [btrfs] [] __btrfs_cow_block+0x303/0x4f0 [btrfs] [] btrfs_cow_block+0x120/0x1f0 [btrfs] [] btrfs_search_slot+0x449/0x930 [btrfs] [] btrfs_lookup_inode+0x2f/0xa0 [btrfs] [] __btrfs_update_delayed_inode+0x1c/0x1d0 [btrfs] [] __btrfs_run_delayed_items+0x162/0x1e0 [btrfs] [] btrfs_delayed_inode_exit+0x3/0x20 [btrfs] [] btrfs_commit_transaction+0x203/0xa50 [btrfs] [] btrfs_sync_fs+0x69/0x110 [btrfs] [] __sync_filesystem+0x30/0x60 [] sync_filesystem+0x4b/0x70 Signed-off-by: Filipe David Borba Manana Signed-off-by: Josef Bacik Signed-off-by: Chris Mason --- diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index a213baf..277fe81 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1600,15 +1600,19 @@ static int btrfs_flush_all_pending_stuffs(struct btrfs_trans_handle *trans, int ret; ret = btrfs_run_delayed_items(trans, root); - if (ret) - return ret; - /* * running the delayed items may have added new refs. account * them now so that they hinder processing of more delayed refs * as little as possible. */ - btrfs_delayed_refs_qgroup_accounting(trans, root->fs_info); + if (ret) { + btrfs_delayed_refs_qgroup_accounting(trans, root->fs_info); + return ret; + } + + ret = btrfs_delayed_refs_qgroup_accounting(trans, root->fs_info); + if (ret) + return ret; /* * rename don't use btrfs_join_transaction, so, once we