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

Gao Xiang hsiangkao at linux.alibaba.com
Tue Jul 15 03:09:36 AEST 2025



On 2025/7/15 00:55, Yifan Zhao wrote:
> 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;

`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


More information about the Linux-erofs mailing list