From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 1/3] fsck.f2fs: fix to avoid memory leak reported by LeakSanitizer
Date: Sat, 15 Aug 2026 08:54:38 +0800 [thread overview]
Message-ID: <20260815005441.1444273-1-chao@kernel.org> (raw)
==5957==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 4096 byte(s) in 1 object(s) allocated from:
#0 0x7f08b78bc340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
#1 0x55b9e0fcbcc7 in update_data_blkaddr /share/tools-f2fs/fsck/mount.c:2523
SUMMARY: AddressSanitizer: 4096 byte(s) leaked in 1 allocation(s).
When a process calls exit(), the C runtime executes all registered
atexit handlers.
AddressSanitizer / LeakSanitizer (LSan) hooks into exit() to inspect
the heap, it checks whether all memory allocated via malloc() / calloc()
was explicitly released.
Relocate sanity check and ASSERT(0) before node block allocation to fix
this issue.
Signed-off-by: Chao Yu <chao@kernel.org>
---
fsck/mount.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fsck/mount.c b/fsck/mount.c
index 2e7ea45..26f213e 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -2520,22 +2520,22 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid,
if (node_blk == NULL) {
struct seg_entry *se;
- node_blk = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1);
- ASSERT(node_blk);
-
get_node_info(sbi, nid, &ni);
- /* read node_block */
- ret = dev_read_block(node_blk, ni.blk_addr);
- ASSERT(ret >= 0);
- node_blk_alloced = true;
-
se = get_seg_entry(sbi, GET_SEGNO(sbi, ni.blk_addr));
if (IS_DATASEG(se->type)) {
ERR_MSG("NAT and SIT is inconsistent: ino: %u, nid: %u, blkaddr: %u, segtype: %d",
ni.ino, ni.nid, ni.blk_addr, se->type);
ASSERT(0);
}
+
+ node_blk = (struct f2fs_node *)calloc(F2FS_BLKSIZE, 1);
+ ASSERT(node_blk);
+
+ /* read node_block */
+ ret = dev_read_block(node_blk, ni.blk_addr);
+ ASSERT(ret >= 0);
+ node_blk_alloced = true;
}
/* check its block address */
--
2.49.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2026-08-15 0:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 0:54 Chao Yu via Linux-f2fs-devel [this message]
2026-08-15 0:54 ` [f2fs-dev] [PATCH 2/3] fsck.f2fs: sanity check i_extra_isize correctly Chao Yu via Linux-f2fs-devel
2026-08-15 0:54 ` [f2fs-dev] [PATCH 3/3] fsck.f2fs: sanity check quota file size in v2_init_io Chao Yu via Linux-f2fs-devel
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=20260815005441.1444273-1-chao@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=chao@kernel.org \
--cc=jaegeuk@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