Subject: [PATCH AUTOSEL 4.19 072/101] perf stat: Fix use-after-freed pointer detected by the smatch tool

From: Sasha Levin <[email-masked]>
Date: Fri, 19 Jul 2019 00:07:03 -0400

From: Leo Yan <[email-masked]>

[ Upstream commit c74b05030edb3b52f4208d8415b8c933bc509a29 ]

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 <[email-masked]>
Acked-by: Jiri Olsa <[email-masked]>
Cc: Adrian Hunter <[email-masked]>
Cc: Alexander Shishkin <[email-masked]>
Cc: Alexey Budankov <[email-masked]>
Cc: Alexios Zavras <[email-masked]>
Cc: Andi Kleen <[email-masked]>
Cc: Changbin Du <[email-masked]>
Cc: Davidlohr Bueso <[email-masked]>
Cc: David S. Miller <[email-masked]>
Cc: Eric Saint-Etienne <[email-masked]>
Cc: Jin Yao <[email-masked]>
Cc: Konstantin Khlebnikov <[email-masked]>
Cc: [email-masked]
Cc: Mathieu Poirier <[email-masked]>
Cc: Namhyung Kim <[email-masked]>
Cc: Peter Zijlstra <[email-masked]>
Cc: Rasmus Villemoes <[email-masked]>
Cc: Song Liu <[email-masked]>
Cc: Suzuki Poulouse <[email-masked]>
Cc: Thomas Gleixner <[email-masked]>
Cc: Thomas Richter <[email-masked]>
Link: http://lkml.kernel.org/r/[email-masked]
Signed-off-by: Arnaldo Carvalho de Melo <[email-masked]>
Signed-off-by: Sasha Levin <[email-masked]>
---
 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 40720150ccd8..789962565c9c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2497,8 +2497,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.20.1

_______________________________________________
linux-arm-kernel mailing list
[email-masked]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel