From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 6/6] btrfs-progs: extent-tree: Fix wrong post order rb tree cleanup for block groups
Date: Tue, 24 Mar 2020 18:53:15 +0800 [thread overview]
Message-ID: <20200324105315.136569-7-wqu@suse.com> (raw)
In-Reply-To: <20200324105315.136569-1-wqu@suse.com>
[BUG]
Valgrind reports memory leak for fsck/012, even after the image is
repair, the memory leak can still be reproduced.
==107060== HEAP SUMMARY:
==107060== in use at exit: 176 bytes in 1 blocks
==107060== total heap usage: 10,647 allocs, 10,646 frees, 3,000,654 bytes allocated
==107060==
==107060== 176 bytes in 1 blocks are definitely lost in loss record 1 of 1
==107060== at 0x483BB65: calloc (vg_replace_malloc.c:762)
==107060== by 0x1BD953: read_one_block_group (extent-tree.c:2661)
==107060== by 0x1BDBD8: btrfs_read_block_groups (extent-tree.c:2719)
==107060== by 0x1B3A2C: btrfs_setup_all_roots (disk-io.c:1024)
==107060== by 0x1B44CA: __open_ctree_fd (disk-io.c:1299)
==107060== by 0x1B46C6: open_ctree_fs_info (disk-io.c:1345)
==107060== by 0x16952E: cmd_check (main.c:10154)
==107060== by 0x11CDC6: cmd_execute (commands.h:125)
==107060== by 0x11D712: main (btrfs.c:386)
==107060==
==107060== LEAK SUMMARY:
==107060== definitely lost: 176 bytes in 1 blocks
==107060== indirectly lost: 0 bytes in 0 blocks
==107060== possibly lost: 0 bytes in 0 blocks
==107060== still reachable: 0 bytes in 0 blocks
==107060== suppressed: 0 bytes in 0 blocks
[CAUSE]
In btrfs_free_block_groups(), we use
rbtree_postorder_for_each_entry_safe() to iterate all block group cache.
However since we're already doing post order iteration, we shouldn't
call rb_erase() during that iteration, as it would re-balance the tree,
and break the post order iteration.
This wrong rb_erase() call leads to above memory leak.
[FIX]
Kill that wrong rb_erase() call.
Fixes: b1bd3cd93fff ("btrfs-progs: reform block groups caches structure")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
extent-tree.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/extent-tree.c b/extent-tree.c
index f0cb9faa4da6..271a2714b889 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -2560,7 +2560,6 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
&info->block_group_cache_tree, cache_node) {
if (!list_empty(&cache->dirty_list))
list_del_init(&cache->dirty_list);
- rb_erase(&cache->cache_node, &info->block_group_cache_tree);
RB_CLEAR_NODE(&cache->cache_node);
if (cache->free_space_ctl) {
btrfs_remove_free_space_cache(cache);
--
2.25.2
next prev parent reply other threads:[~2020-03-24 10:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 10:53 [PATCH 0/6] btrfs-progs: Fixes for valgrind errors during fsck-tests Qu Wenruo
2020-03-24 10:53 ` [PATCH 1/6] btrfs-progs: tests/common: Don't call INSTRUMENT on mount command Qu Wenruo
2020-03-24 10:53 ` [PATCH 2/6] btrfs-progs: check/original: Fix uninitialized stack memory access for deal_root_from_list() Qu Wenruo
2020-03-24 10:53 ` [PATCH 3/6] btrfs-progs: check/original: Fix uninitialized memory for newly allocated data_backref Qu Wenruo
2020-03-24 10:53 ` [PATCH 4/6] btrfs-progs: check/original: Fix uninitialized return value from btrfs_write_dirty_block_groups() Qu Wenruo
2020-03-24 10:53 ` [PATCH 5/6] btrfs-progs: check/original: Fix uninitialized extent buffer contents Qu Wenruo
2020-03-24 10:53 ` Qu Wenruo [this message]
2020-03-25 14:42 ` [PATCH 0/6] btrfs-progs: Fixes for valgrind errors during fsck-tests David Sterba
2020-03-26 0:59 ` Qu Wenruo
2020-03-27 15:27 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200324105315.136569-7-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox