diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 10db1e5f1e6c..60d1f166629e 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -726,8 +726,11 @@ static int report__collapse_hists(struct report *rep) evlist__for_each_entry(rep->session->evlist, pos) { struct hists *hists = evsel__hists(pos); - if (pos->core.idx == 0) - hists->symbol_filter_str = rep->symbol_filter_str; + if (pos->core.idx == 0) { + hists->symbol_filter_str = + rep->symbol_filter_str ? + strdup(rep->symbol_filter_str) : NULL; + } hists->socket_filter = rep->socket_filter; diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index b6002724bc3a..be8a6b169722 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -3220,7 +3220,10 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h "To remove the filter later, press / + ENTER.", buf, "ENTER: OK, ESC: Cancel", delay_secs * 2) == K_ENTER) { - hists->symbol_filter_str = *buf ? buf : NULL; + char *new_filter = *buf ? strdup(buf) : NULL; + + zfree(&hists->symbol_filter_str); + hists->symbol_filter_str = new_filter; hists__filter_by_symbol(hists); hist_browser__reset(browser); } diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index c93915625ee7..443694926f1a 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -3056,6 +3056,7 @@ static void hists_evsel__exit(struct evsel *evsel) struct perf_hpp_list_node *node, *tmp; hists__delete_all_entries(hists); + zfree(&hists->symbol_filter_str); zfree(&hists->mem_stat_types); zfree(&hists->mem_stat_total);