From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH v2 1/4] btrfs-progs: corrupt-block: fix memory leak in debug_corrupt_sector()
Date: Wed, 5 Jun 2024 09:13:41 +0930 [thread overview]
Message-ID: <3d9a9ecd46165c18f4ccd15f4e7aad489343dabe.1717544015.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1717544015.git.wqu@suse.com>
ASAN build (make D=asan) would cause memory leak for
btrfs-corrupt-block inside debug_corrupt_sector().
This can be reproduced by fsck/013 test case.
The cause is pretty simple, we just malloc a sector and forgot to free
it.
Issue: #806
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
btrfs-corrupt-block.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 124597333771..e88319891910 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -70,7 +70,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
if (ret < 0) {
errno = -ret;
error("cannot read bytenr %llu: %m", logical);
- return ret;
+ goto out;
}
printf("corrupting %llu copy %d\n", logical, mirror_num);
memset(buf, 0, sectorsize);
@@ -78,7 +78,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
if (ret < 0) {
errno = -ret;
error("cannot write bytenr %llu: %m", logical);
- return ret;
+ goto out;
}
}
@@ -90,7 +90,8 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
if (mirror_num > num_copies)
break;
}
-
+out:
+ free(buf);
return 0;
}
--
2.45.2
next prev parent reply other threads:[~2024-06-04 23:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-04 23:43 [PATCH v2 0/4] btrfs-progs: small bug fixes Qu Wenruo
2024-06-04 23:43 ` Qu Wenruo [this message]
2024-06-04 23:43 ` [PATCH v2 2/4] btrfs-progs: print-tree: do sanity checks for dir items Qu Wenruo
2024-06-04 23:43 ` [PATCH v2 3/4] btrfs-progs: error out immediately if an unknown backref type is hit Qu Wenruo
2024-06-04 23:43 ` [PATCH v2 4/4] btrfs-progs: fix misc/038 test cases Qu Wenruo
2024-06-05 17:57 ` [PATCH v2 0/4] btrfs-progs: small bug fixes 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=3d9a9ecd46165c18f4ccd15f4e7aad489343dabe.1717544015.git.wqu@suse.com \
--to=wqu@suse.com \
--cc=josef@toxicpanda.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