Re: [PATCH v1 02/11] perf stat: Smatch: Fix use-after-freed pointer
From: Arnaldo Carvalho de Melo
Date: Wed Jul 03 2019 - 14:18:53 EST
Em Tue, Jul 02, 2019 at 06:34:11PM +0800, Leo Yan escreveu:
> Based on the following report from Smatch, fix the use-after-freed
> pointer.
>
> tools/perf/builtin-stat.c:1353
> add_default_attributes() warn: passing freed memory 'str'.
>
> The pointer 'str' has been freed but later it is still passed into the
> function parse_events_print_error(). This patch fixes this
> use-after-freed issue.
thanks, applied.
> Signed-off-by: Leo Yan <leo.yan@xxxxxxxxxx>
> ---
> tools/perf/builtin-stat.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 8a35fc5a7281..de0f6d0e96a2 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -1349,8 +1349,8 @@ static int add_default_attributes(void)
> fprintf(stderr,
> "Cannot set up top down events %s: %d\n",
> str, err);
> - free(str);
> parse_events_print_error(&errinfo, str);
> + free(str);
> return -1;
> }
> } else {
> --
> 2.17.1
--
- Arnaldo