[PATCH v1] erofs-utils:mount: fix memory leak in erofs_nbd_get_identifier

Gao Xiang hsiangkao at linux.alibaba.com
Tue Sep 9 17:28:18 AEST 2025



On 2025/9/9 14:55, ChengyuZhu6 wrote:
> From: Chengyu Zhu <hudsonzhu at tencent.com>
> 
> The erofs_nbd_get_identifier() function returns dynamically allocated
> memory via getline(), but the caller in erofsmount_nbd() was not
> freeing this memory, causing a 120-byte memory leak.
> 
> Add proper memory cleanup by calling free(id) when the identifier
> is not an error pointer.
> 
> Signed-off-by: Chengyu Zhu <hudsonzhu at tencent.com>

The subject line should be fixed from:

`erofs-utils:mount: fix memory leak in erofs_nbd_get_identifier`
              ^
to
`erofs-utils: mount: fix memory leak in erofs_nbd_get_identifier`

Otherwise it looks good to me, will apply.

Thanks,
Gao Xiang

> ---
>   mount/main.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/mount/main.c b/mount/main.c
> index 0daf232..d4f1cda 100644
> --- a/mount/main.c
> +++ b/mount/main.c
> @@ -741,6 +741,8 @@ static int erofsmount_nbd(struct erofs_nbd_source *source,
>   			if (err)
>   				erofs_warn("failed to turn on autoclear for nbd%d: %s",
>   					   num, erofs_strerror(err));
> +			if (!IS_ERR(id))
> +				free(id);
>   		}
>   	}
>   	return err;



More information about the Linux-erofs mailing list