Re: [PATCH v3 10/10] perf list: Add json output option

From: Arnaldo Carvalho de Melo
Date: Wed Nov 16 2022 - 07:00:07 EST


Em Wed, Nov 16, 2022 at 08:35:28AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Please always run 'perf test' before and after your patches and before
> > sending it upstream.

> Running as !root on a different machine I get some other interesting
> info:

> ⬢[acme@toolbox perf]$ perf list syscalls:sys_enter_open*
> double free or corruption (fasttop)
> Aborted (core dumped)
> ⬢[acme@toolbox perf]$
>
> That is:
>
> free(ps.pmu_glob);
>
>
> at the end of cmd_list().

This plus the change to default_ps in the subsequent patch cures the
double free, now working on the segfault.

diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 12811fc40a3067cc..ce62a2fdcbd6ca61 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -329,6 +329,7 @@ int cmd_list(int argc, const char **argv)
metricgroup__print(&print_cb, &ps);
} else if ((sep = strchr(argv[i], ':')) != NULL) {
int sep_idx;
+ char *old_pmu_glob = ps.pmu_glob;

sep_idx = sep - argv[i];
s = strdup(argv[i]);
@@ -346,6 +347,7 @@ int cmd_list(int argc, const char **argv)
ps.metricgroups = true;
metricgroup__print(&print_cb, &ps);
free(s);
+ ps.pmu_glob = old_pmu_glob;
} else {
if (asprintf(&s, "*%s*", argv[i]) < 0) {
printf("Critical: Not enough memory! Trying to continue...\n");