Commit-ID: c74b05030edb3b52f4208d8415b8c933bc509a29 Gitweb: https://git.kernel.org/tip/c74b05030edb3b52f4208d8415b8c933bc509a29 Author: Leo Yan <leo....@linaro.org> AuthorDate: Tue, 2 Jul 2019 18:34:11 +0800 Committer: Arnaldo Carvalho de Melo <a...@redhat.com> CommitDate: Tue, 9 Jul 2019 09:33:54 -0300
perf stat: Fix use-after-freed pointer detected by the smatch tool 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....@linaro.org> Acked-by: Jiri Olsa <jo...@kernel.org> Cc: Adrian Hunter <adrian.hun...@intel.com> Cc: Alexander Shishkin <alexander.shish...@linux.intel.com> Cc: Alexey Budankov <alexey.budan...@linux.intel.com> Cc: Alexios Zavras <alexios.zav...@intel.com> Cc: Andi Kleen <a...@linux.intel.com> Cc: Changbin Du <changbin...@intel.com> Cc: Davidlohr Bueso <d...@stgolabs.net> Cc: David S. Miller <da...@davemloft.net> Cc: Eric Saint-Etienne <eric.saint.etie...@oracle.com> Cc: Jin Yao <yao....@linux.intel.com> Cc: Konstantin Khlebnikov <khlebni...@yandex-team.ru> Cc: linux-arm-ker...@lists.infradead.org Cc: Mathieu Poirier <mathieu.poir...@linaro.org> Cc: Namhyung Kim <namhy...@kernel.org> Cc: Peter Zijlstra <pet...@infradead.org> Cc: Rasmus Villemoes <li...@rasmusvillemoes.dk> Cc: Song Liu <songliubrav...@fb.com> Cc: Suzuki Poulouse <suzuki.poul...@arm.com> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Thomas Richter <tmri...@linux.ibm.com> Link: http://lkml.kernel.org/r/20190702103420.27540-3-leo....@linaro.org Signed-off-by: Arnaldo Carvalho de Melo <a...@redhat.com> --- 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 e5e19b461061..b81f7b197d24 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 {