From: Yifan Zhao <stopire@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: Yifan Zhao <stopire@gmail.com>
Subject: [PATCH 2/2] erofs-utils: lib: add guard clause for z_erofs_compress_init
Date: Sat, 12 Jul 2025 00:16:15 +0800 [thread overview]
Message-ID: <20250711161615.44832-3-stopire@gmail.com> (raw)
In-Reply-To: <20250711161615.44832-1-stopire@gmail.com>
Currently, `z_erofs_compress_init` allocates heap memory for `zmgr` even
when compression is disabled, causing a memory leak. Let's add a guard
clause to skip this allocation.
Fixes: a110eea6d80a ("erofs-utils: mkfs: avoid erroring out if `zmgr` is uninitialized")
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
lib/compress.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/compress.c b/lib/compress.c
index bf47121..09b943f 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -2027,6 +2027,11 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi, struct erofs_buffer_head *s
u32 max_dict_size[Z_EROFS_COMPRESSION_MAX] = {};
u32 available_compr_algs = 0;
+ /* compression not enabled */
+ if (!cfg.c_compr_opts[0].alg) {
+ return 0;
+ }
+
if (!sbi->zmgr) {
sbi->zmgr = calloc(1, sizeof(*sbi->zmgr));
if (!sbi->zmgr)
--
2.43.0
next prev parent reply other threads:[~2025-07-11 16:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 16:16 [PATCH 0/2] two minor fixes for erofs-utils lib Yifan Zhao
2025-07-11 16:16 ` [PATCH 1/2] erofs-utils: lib: fix uninitialized variable access in bmgr Yifan Zhao
2025-07-11 16:40 ` Gao Xiang
2025-07-11 16:16 ` Yifan Zhao [this message]
2025-07-11 16:39 ` [PATCH 2/2] erofs-utils: lib: add guard clause for z_erofs_compress_init Gao Xiang
2025-07-14 16:55 ` [PATCH v2 2/2] erofs-utils: lib: fix memory leak in z_erofs_compress_exit Yifan Zhao
2025-07-14 17:09 ` Gao Xiang
2025-07-15 15:21 ` [PATCH v3 " Yifan Zhao
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=20250711161615.44832-3-stopire@gmail.com \
--to=stopire@gmail.com \
--cc=linux-erofs@lists.ozlabs.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.