Re: [PATCH 08/38] trace-cmd lib: prevent a memory leak in create_event_list_item()

Steven Rostedt <[email protected]>
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
On Wed,  5 Jun 2024 15:40:23 +0200
"Jerome Marchand" <[email protected]> wrote:

> Free ptr if malloc() fails.
> 
> Fixes a RESOURCE_LEAK error (CWE-772)
> 
> Signed-off-by: Jerome Marchand <[email protected]>
> ---
>  lib/trace-cmd/trace-output.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
> index 59498edc..4a9ecc5d 100644
> --- a/lib/trace-cmd/trace-output.c
> +++ b/lib/trace-cmd/trace-output.c
> @@ -955,7 +955,8 @@ create_event_list_item(struct tracecmd_output *handle,
>  	free(str);
>  	return;
>   err_mem:
> -	 tracecmd_warning("Insufficient memory");
> +	free(ptr);
> +	tracecmd_warning("Insufficient memory");

This function starts with:

	char *ptr;
	char *str;

	str = strdup(list->glob);
	if (!str)
		goto err_mem;

Where ptr is not defined yet.

I'm going to skip this patch.

-- Steve

>  }
>  
>  static int read_ftrace_files(struct tracecmd_output *handle, bool compress)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.