Re: [PATCH 2/2] libtraceevent: fix free NULL pointer in parse_arg_add()

From: Steven Rostedt
Date: Fri Jun 17 2022 - 17:44:38 EST


On Fri, 13 May 2022 10:33:08 +0800
Wang ShaoBo <bobo.shaobowang@xxxxxxxxxx> wrote:

> Should not call free if parg->format is NULL.
>
> Fixes: e7a90882b05b ("tools lib traceevent: Optimize pretty_print() function")
> Signed-off-by: Wang ShaoBo <bobo.shaobowang@xxxxxxxxxx>
> ---
> tools/lib/traceevent/event-parse.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
> index 69e4d5229362..b1a07db54457 100644
> --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/lib/traceevent/event-parse.c
> @@ -5461,9 +5461,11 @@ static int parse_arg_add(struct tep_print_parse **parse, char *format,
> return 0;
> error:
> if (parg) {
> - free(parg->format);
> + if (parg->format)
> + free(parg->format);

It's perfectly fine to call free(NULL).

This is not a bug fix.

-- Steve

> free(parg);
> }
> +
> return -1;
> }
>