[tip: perf/core] perf parse: Add a deep delete for parse event terms
From: tip-bot2 for Ian Rogers
Date: Tue Nov 12 2019 - 06:18:28 EST
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 1dc925568f015edfdbb89e20ad41755bb70538b9
Gitweb: https://git.kernel.org/tip/1dc925568f015edfdbb89e20ad41755bb70538b9
Author: Ian Rogers <irogers@xxxxxxxxxx>
AuthorDate: Wed, 30 Oct 2019 15:34:47 -07:00
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitterDate: Thu, 07 Nov 2019 08:30:18 -03:00
perf parse: Add a deep delete for parse event terms
Add a parse_events_term deep delete function so that owned strings and
arrays are freed.
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Alexei Starovoitov <ast@xxxxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
Cc: Jin Yao <yao.jin@xxxxxxxxxxxxxxx>
Cc: John Garry <john.garry@xxxxxxxxxx>
Cc: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Cc: Martin KaFai Lau <kafai@xxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Song Liu <songliubraving@xxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Cc: Yonghong Song <yhs@xxxxxx>
Cc: bpf@xxxxxxxxxxxxxxx
Cc: clang-built-linux@xxxxxxxxxxxxxxxx
Cc: netdev@xxxxxxxxxxxxxxx
Link: http://lore.kernel.org/lkml/20191030223448.12930-10-irogers@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/parse-events.c | 16 +++++++++++++---
tools/perf/util/parse-events.h | 1 +
tools/perf/util/parse-events.y | 12 ++----------
tools/perf/util/pmu.c | 2 +-
4 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index a0a80f4..6d18ff9 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2812,6 +2812,18 @@ int parse_events_term__clone(struct parse_events_term **new,
return new_term(new, &temp, str, 0);
}
+void parse_events_term__delete(struct parse_events_term *term)
+{
+ if (term->array.nr_ranges)
+ zfree(&term->array.ranges);
+
+ if (term->type_val != PARSE_EVENTS__TERM_TYPE_NUM)
+ zfree(&term->val.str);
+
+ zfree(&term->config);
+ free(term);
+}
+
int parse_events_copy_term_list(struct list_head *old,
struct list_head **new)
{
@@ -2842,10 +2854,8 @@ void parse_events_terms__purge(struct list_head *terms)
struct parse_events_term *term, *h;
list_for_each_entry_safe(term, h, terms, list) {
- if (term->array.nr_ranges)
- zfree(&term->array.ranges);
list_del_init(&term->list);
- free(term);
+ parse_events_term__delete(term);
}
}
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 34f58d2..5ee8ac9 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -139,6 +139,7 @@ int parse_events_term__sym_hw(struct parse_events_term **term,
char *config, unsigned idx);
int parse_events_term__clone(struct parse_events_term **new,
struct parse_events_term *term);
+void parse_events_term__delete(struct parse_events_term *term);
void parse_events_terms__delete(struct list_head *terms);
void parse_events_terms__purge(struct list_head *terms);
void parse_events__clear_array(struct parse_events_array *a);
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 376b198..4cac830 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -49,14 +49,6 @@ static void free_list_evsel(struct list_head* list_evsel)
free(list_evsel);
}
-static void free_term(struct parse_events_term *term)
-{
- if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR)
- free(term->val.str);
- zfree(&term->array.ranges);
- free(term);
-}
-
static void inc_group_count(struct list_head *list,
struct parse_events_state *parse_state)
{
@@ -99,7 +91,7 @@ static void inc_group_count(struct list_head *list,
%type <str> PE_DRV_CFG_TERM
%destructor { free ($$); } <str>
%type <term> event_term
-%destructor { free_term ($$); } <term>
+%destructor { parse_events_term__delete ($$); } <term>
%type <list_terms> event_config
%type <list_terms> opt_event_config
%type <list_terms> opt_pmu_config
@@ -694,7 +686,7 @@ event_config ',' event_term
struct parse_events_term *term = $3;
if (!head) {
- free_term(term);
+ parse_events_term__delete(term);
YYABORT;
}
list_add_tail(&term->list, head);
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index f9f427d..db1e571 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1260,7 +1260,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
info->metric_name = alias->metric_name;
list_del_init(&term->list);
- free(term);
+ parse_events_term__delete(term);
}
/*