[PATCH v3 2/2] erofs-utils: lib: fix memory leak in z_erofs_compress_exit

Yifan Zhao stopire at gmail.com
Wed Jul 16 01:21:11 AEST 2025


Currently, `z_erofs_compress_exit` does not free `zmgr` if compression
is disabled, causing a memory leak. Fix it.

Fixes: a110eea6d80a ("erofs-utils: mkfs: avoid erroring out if `zmgr` is uninitialized")
Signed-off-by: Yifan Zhao <stopire at gmail.com>
---
change since v2:
- do not remove early exit in `z_erofs_compress_exit`.

 lib/compress.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/compress.c b/lib/compress.c
index a57bb6a..2059e19 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -2140,6 +2140,9 @@ int z_erofs_compress_exit(struct erofs_sb_info *sbi)
 			return ret;
 	}
 
+	if (sbi->zmgr)
+		free(sbi->zmgr);
+
 	if (z_erofs_mt_enabled) {
 #ifdef EROFS_MT_ENABLED
 		ret = erofs_destroy_workqueue(&z_erofs_mt_ctrl.wq);
-- 
2.43.0



More information about the Linux-erofs mailing list