[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-keyrings
Subject:    Re: [PATCH] sign-file: fix memory leak
From:       "Jarkko Sakkinen" <jarkko () kernel ! org>
Date:       2023-06-09 17:45:17
Message-ID: CT8B23KI5MSP.2RS13WHU6LH7J () suppilovahvero
[Download RAW message or body]

On Thu May 25, 2023 at 11:43 AM EEST, Tianjia Zhang wrote:
> The buffer allocated by asprintf() must be freeed.

... and it is freed by do_exit().

Short summary should really be

"sign-file: Explicitly call free(sig_file_name)"

David, what do you think of this patch is general?

Again, as an independent patch it is not really doing much at all.
Since freeing resources is a good practice, it would make sense as
a step toward doing something functionally interesting.

> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
> ---
>  scripts/sign-file.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/sign-file.c b/scripts/sign-file.c
> index b90fc9f7437f..94267cf72197 100644
> --- a/scripts/sign-file.c
> +++ b/scripts/sign-file.c
> @@ -369,6 +369,7 @@ int main(int argc, char **argv)
>  			    "%s", sig_file_name);
>  #endif
>  			BIO_free(b);
> +			free(sig_file_name);
>  		}
>  
>  		if (sign_only) {
> @@ -420,8 +421,10 @@ int main(int argc, char **argv)
>  	ERR(BIO_free(bd) < 0, "%s", dest_name);
>  
>  	/* Finally, if we're signing in place, replace the original. */
> -	if (replace_orig)
> +	if (replace_orig) {
>  		ERR(rename(dest_name, module_name) < 0, "%s", dest_name);
> +		free(dest_name);
> +	}
>  
>  	return 0;
>  }
> -- 
> 2.24.3 (Apple Git-128)

BR, Jarkko
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic