[PATCH 2/2] erofs-utils: lib: add guard clause for z_erofs_compress_init

Yifan Zhao stopire at gmail.com
Sat Jul 12 02:16:15 AEST 2025


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 at 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



More information about the Linux-erofs mailing list