diff mbox series

[v1,02/11] perf stat: Smatch: Fix use-after-freed pointer

Message ID 20190702103420.27540-3-leo.yan@linaro.org (mailing list archive)
State New, archived
Headers show
Series perf: Fix errors detected by Smatch | expand

Commit Message

Leo Yan July 2, 2019, 10:34 a.m. UTC
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.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/builtin-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Arnaldo Carvalho de Melo July 3, 2019, 6:18 p.m. UTC | #1
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@linaro.org>
> ---
>  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
diff mbox series

Patch

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 {