btrfs: fix resource leak in do_walk_down()
Subsystems (2)
PATCH 1/1 btrfs: fix resource leak in do_walk_down()
When check_next_block_uptodate() fails, do_walk_down() returns directly without cleaning up the locked extent buffer allocated earlier, causing memory and lock leaks.
Fix by using the existing out_unlock cleanup path instead of direct return.
--- fs/btrfs/extent-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/extent-tree.c +1 -1
@@ -5770,7 +5770,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ret =check_next_block_uptodate (trans, root, path, wc, next);if (ret) -return ret; + goto out_unlock; level--;ASSERT (level ==btrfs_header_level (next));
Signature · 1 line
2.20.1
Quoted 20 lines · Zhen Ni
When
check_next_block_uptodate()fails,do_walk_down()returns directly without cleaning up the locked extent buffer allocated earlier, causing memory and lock leaks.Fix by using the existing
out_unlockcleanup path instead of direct return.Fixes 562d425454e8 ("btrfs: factor out eb uptodate check from do_walk_down()")Signed-off-by Zhen Ni <[email protected]>--- fs/btrfs/extent-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/extent-tree.c +0
-0
fs/btrfs/extent-tree.c static noinline int do_walk_down(struct btrfs_trans_handle *trans, · line 5773
Quoted 5 lines
fs/btrfs/extent-tree.c +1
-1@@ -5770,7 +5770,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ret =check_next_block_uptodate (trans, root, path, wc, next);if (ret) -return ret; + goto out_unlock;
This is wrong and will cause a double unlock and double free.
When check_next_block_uptodate() returns an error, it has already unlocked and freed the extent buffer.
Thanks.
Quoted 7 lines
fs/btrfs/extent-tree.c +0
-1level--;ASSERT (level ==btrfs_header_level (next)); --2.20.1