two minor fixes for erofs-utils lib
cover two minor fixes for erofs-utils lib
Fix following issues during basic usage of mkfs.erofs.
Yifan Zhao (2):
erofs-utils: lib: fix uninitialized variable access in bmgr
erofs-utils: lib: add guard clause for z_erofs_compress_init
lib/cache.c | 1 + lib/compress.c | 5 +++++ 2 files changed, 6 insertions(+)
Signature · 1 line
2.43.0
PATCH 1/2 erofs-utils: lib: fix uninitialized variable access in bmgr
Missing bmgr->metablkcnt initialization leads to an uninitialized variable access, fix it.
--- lib/cache.c | 1 + 1 file changed, 1 insertion(+)
lib/cache.c +1 -0
@@ -52,6 +52,7 @@ struct erofs_bufmgr *erofs_buffer_init(struct erofs_sb_info *sbi, bmgr->blkh.blkaddr =EROFS_NULL_ADDR ; bmgr->tail_blkaddr = startblk; bmgr->last_mapped_block = &bmgr->blkh; + bmgr->metablkcnt =0 ; bmgr->dsunit =0 ;return bmgr; }
Signature · 1 line
2.43.0
PATCH 2/2 erofs-utils: lib: add guard clause for z_erofs_compress_init
In reply to Yifan ZhaoCurrently, 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.
--- lib/compress.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/compress.c +5 -0
@@ -2027,6 +2027,11 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi, struct erofs_buffer_head *su32 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)
Signature · 1 line
2.43.0
Re: [PATCH 2/2] erofs-utils: lib: add guard clause for z_erofs_compress_init
Hi Yifan,
Quoted 3 lines · Yifan Zhao
Currently,
z_erofs_compress_initallocates heap memory forzmgreven when compression is disabled, causing a memory leak. Let's add a guard clause to skip this allocation.
I think we should free(zmgr) in z_erofs_compress_exit() instead.
allocates zmgr is not a major issue, but I tend to cleanup cfg.c_compr_opts and even cfg soon.
Thanks,
Gao Xiang
Re: [PATCH 1/2] erofs-utils: lib: fix uninitialized variable access in bmgr
In reply to Yifan ZhaoQuoted 4 lines · Yifan Zhao
Missing
bmgr->metablkcntinitialization leads to an uninitialized variable access, fix it.Signed-off-by Yifan Zhao <[email protected]>
Thanks,
Gao Xiang
PATCH v2 2/2 erofs-utils: lib: fix memory leak in z_erofs_compress_exit
In reply to Gao XiangCurrently, z_erofs_compress_exit does not free zmgr if compression is disabled, causing a memory leak. Fix it.
---
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(-)
lib/compress.c +3 -4
@@ -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);
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] erofs-utils: lib: fix memory leak in z_erofs_compress_exit
Quoted 17 lines · Yifan Zhao
Currently,
z_erofs_compress_exitdoes not freezmgrif 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 <[email protected]>---
change since v1:
- freezmgrinz_erofs_compress_exitrather than allocating it inz_erofs_compress_initconditionally.lib/compress.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)lib/compress.c +0
-0
lib/compress.c int z_erofs_compress_exit(struct erofs_sb_info *sbi) · line 2135
Quoted 6 lines
lib/compress.c +0
-3@@ -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 ;
sbi->zmgr still can be NULL if z_erofs_compress_init() is not called, or sbi->zmgr = calloc(1, sizeof(*sbi->zmgr)); fails.
Thanks,
Gao Xiang
PATCH v3 2/2 erofs-utils: lib: fix memory leak in z_erofs_compress_exit
Currently, z_erofs_compress_exit does not free zmgr if compression is disabled, causing a memory leak. Fix it.
---
change since v2:
- do not remove early exit in z_erofs_compress_exit.
lib/compress.c | 3 +++ 1 file changed, 3 insertions(+)
lib/compress.c +3 -0
@@ -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);
Signature · 1 line
2.43.0