perf parse-events: Fix 3 use after frees found with clang ASAN
authorIan Rogers <irogers@google.com>
Sat, 14 Mar 2020 17:03:56 +0000 (10:03 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 23 Mar 2020 14:08:29 +0000 (11:08 -0300)
Reproducible with a clang asan build and then running perf test in
particular 'Parse event definition strings'.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: clang-built-linux@googlegroups.com
Link: http://lore.kernel.org/lkml/20200314170356.62914-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c
tools/perf/util/parse-events.c

index 816d930d774e726200b74abc5b60e7929d9160a0..15ccd193483f190be2e33a48433ee914e566c046 100644 (file)
@@ -1287,6 +1287,7 @@ void perf_evsel__exit(struct evsel *evsel)
        perf_thread_map__put(evsel->core.threads);
        zfree(&evsel->group_name);
        zfree(&evsel->name);
+       zfree(&evsel->pmu_name);
        perf_evsel__object.fini(evsel);
 }
 
index a7dc0b09697469eb6773b41d6a5c1b9652136f86..10107747b36176f2b49ee7aa65f2607de5645fe6 100644 (file)
@@ -1449,7 +1449,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
                evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL,
                                    auto_merge_stats, NULL);
                if (evsel) {
-                       evsel->pmu_name = name;
+                       evsel->pmu_name = name ? strdup(name) : NULL;
                        evsel->use_uncore_alias = use_uncore_alias;
                        return 0;
                } else {
@@ -1497,7 +1497,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
                evsel->snapshot = info.snapshot;
                evsel->metric_expr = info.metric_expr;
                evsel->metric_name = info.metric_name;
-               evsel->pmu_name = name;
+               evsel->pmu_name = name ? strdup(name) : NULL;
                evsel->use_uncore_alias = use_uncore_alias;
                evsel->percore = config_term_percore(&evsel->config_terms);
        }
@@ -1547,7 +1547,7 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
                                if (!parse_events_add_pmu(parse_state, list,
                                                          pmu->name, head,
                                                          true, true)) {
-                                       pr_debug("%s -> %s/%s/\n", config,
+                                       pr_debug("%s -> %s/%s/\n", str,
                                                 pmu->name, alias->str);
                                        ok++;
                                }