[PATCH v2 2/2] erofs-utils: lib: fix memory leak in z_erofs_compress_exit
Yifan Zhao
stopire at gmail.com
Tue Jul 15 02:55:42 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 v1:
- free `zmgr` in `z_erofs_compress_exit` rather than allocating it in `z_erofs_compress_init` conditionally.
lib/compress.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/compress.c b/lib/compress.c
index a57bb6a..3c87a28 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -2130,16 +2130,15 @@ int z_erofs_compress_exit(struct erofs_sb_info *sbi)
{
int i, ret;
- /* If `zmgr` is uninitialized, return directly. */
- if (!sbi->zmgr)
- return 0;
-
for (i = 0; cfg.c_compr_opts[i].alg; ++i) {
ret = erofs_compressor_exit(&sbi->zmgr->ccfg[i].handle);
if (ret)
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