[PATCH 15/15] perf parse: Use YYABORT to clear stack after failure, plugging leaks

From: Arnaldo Carvalho de Melo
Date: Tue Nov 12 2019 - 13:39:25 EST


From: Ian Rogers <irogers@xxxxxxxxxx>

Using return rather than YYABORT means that the stack isn't cleared up
following a failure. The change to YYABORT means the return value is 1
rather than -1, but the callers just check for a result of 0 (success).
Add missing free of a list when an error occurs in event_pmu.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Link: http://lore.kernel.org/lkml/20191109075840.181231-1-irogers@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/parse-events.y | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 4cac830015be..e2eea4e601b4 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -284,6 +284,7 @@ PE_NAME opt_pmu_config
do { \
parse_events_terms__delete($2); \
parse_events_terms__delete(orig_terms); \
+ free(list); \
free($1); \
free(pattern); \
YYABORT; \
@@ -550,7 +551,7 @@ tracepoint_name opt_event_config
free($1.event);
if (err) {
free(list);
- return -1;
+ YYABORT;
}
$$ = list;
}
--
2.21.0