[PATCH RESEND] erofs-utils: fix a memory leak of multiple devices

Gao Xiang hsiangkao at linux.alibaba.com
Fri Jul 22 13:28:27 AEST 2022


Hi Yue,

On Fri, Jul 22, 2022 at 11:10:08AM +0800, Yue Hu wrote:
> The memory allocated for multiple devices should be freed when to exit.
> Let's add a helper to fix it since there is more than one to use it.
> 
> Signed-off-by: Yue Hu <huyue2 at coolpad.com>
> ---
>  dump/main.c              | 7 ++++---
>  fsck/main.c              | 7 ++++---
>  fuse/main.c              | 5 +++--
>  include/erofs/internal.h | 1 +
>  lib/super.c              | 6 ++++++
>  5 files changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/dump/main.c b/dump/main.c
> index 40e850a..c9b3a8f 100644
> --- a/dump/main.c
> +++ b/dump/main.c
> @@ -615,7 +615,7 @@ int main(int argc, char **argv)
>  	err = erofs_read_superblock();
>  	if (err) {
>  		erofs_err("failed to read superblock");
> -		goto exit_dev_close;
> +		goto exit_put_super;
>  	}
>  
>  	if (!dumpcfg.totalshow) {
> @@ -630,13 +630,14 @@ int main(int argc, char **argv)
>  
>  	if (dumpcfg.show_extent && !dumpcfg.show_inode) {
>  		usage();
> -		goto exit_dev_close;
> +		goto exit_put_super;
>  	}
>  
>  	if (dumpcfg.show_inode)
>  		erofsdump_show_fileinfo(dumpcfg.show_extent);
>  
> -exit_dev_close:
> +exit_put_super:
> +	erofs_put_super();
>  	dev_close();
>  exit:
>  	blob_closeall();
> diff --git a/fsck/main.c b/fsck/main.c
> index 5a2f659..a8f0e24 100644
> --- a/fsck/main.c
> +++ b/fsck/main.c
> @@ -813,12 +813,12 @@ int main(int argc, char **argv)
>  	err = erofs_read_superblock();
>  	if (err) {
>  		erofs_err("failed to read superblock");
> -		goto exit_dev_close;
> +		goto exit_put_super;

Why do we call erofs_put_super() again here? I think we don't need to
call erofs_put_super for all failed paths.

Thanks,
Gao Xiang


More information about the Linux-erofs mailing list