[PATCH v2] erofs-utils: fix memory leak when erofs_fill_inode() fails

Gao Xiang hsiangkao at redhat.com
Wed Jan 20 02:36:20 AEDT 2021


Hi Weiwen,

On Tue, Jan 19, 2021 at 02:11:23PM +0800, Hu Weiwen wrote:
> Signed-off-by: Hu Weiwen <sehuww at mail.scut.edu.cn>
> ---
> fixes a typo in v1
> 
>  lib/inode.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/inode.c b/lib/inode.c
> index d6a64cc..6f6e984 100644
> --- a/lib/inode.c
> +++ b/lib/inode.c
> @@ -868,9 +868,13 @@ struct erofs_inode *erofs_iget_from_path(const char *path, bool is_src)
> 
>  	ret = erofs_fill_inode(inode, &st, path);
>  	if (ret)
> -		return ERR_PTR(ret);
> +		goto err;
> 
>  	return inode;
> +
> +err:
> +	free(inode);
> +	return ERR_PTR(ret);

Yeah, I think many error paths now might have memory leak, yet I'm not sure
if these does matter since the program would be exited soon... (since liberofs
doesn't export as a public library for now since I don't think these APIs are
finalized to public...)

Since there is the only one user of this label... So I think we might inline
such error path until more users exist?

Otherwise it looks good to me.

Thanks,
Gao Xiang

>  }
> 
>  void erofs_fixup_meta_blkaddr(struct erofs_inode *rootdir)
> --
> 2.30.0
> 



More information about the Linux-erofs mailing list