All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: free list on error path parsing events
@ 2013-07-07 20:43 David Ahern
  0 siblings, 0 replies; only message in thread
From: David Ahern @ 2013-07-07 20:43 UTC (permalink / raw)
  To: acme, linux-kernel
  Cc: David Ahern, Ingo Molnar, Frederic Weisbecker, Peter Zijlstra,
	Jiri Olsa, Namhyung Kim

5f48cb6 moved list memory allocations into parse-events.y. That memory
needs to be freed on a parse failure.

Reported-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/parse-events.y |   41 ++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 4eb67ec..85d0999 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -22,6 +22,14 @@ do { \
 		YYABORT; \
 } while (0)
 
+#define ABORT_ON_FREE(val, p) \
+do { \
+	if (val) { \
+		free(p); \
+		YYABORT; \
+	} \
+} while (0)
+
 #define ALLOC_LIST(list) \
 do { \
 	list = malloc(sizeof(*list)); \
@@ -206,7 +214,7 @@ PE_NAME '/' event_config '/'
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, $3));
+	ABORT_ON_FREE(parse_events_add_pmu(list, &data->idx, $1, $3), list);
 	parse_events__free_terms($3);
 	$$ = list;
 }
@@ -225,8 +233,8 @@ value_sym '/' event_config '/'
 	int config = $1 & 255;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_numeric(list, &data->idx,
-					  type, config, $3));
+	ABORT_ON_FREE(parse_events_add_numeric(list, &data->idx,
+					  type, config, $3), list);
 	parse_events__free_terms($3);
 	$$ = list;
 }
@@ -239,8 +247,8 @@ value_sym sep_slash_dc
 	int config = $1 & 255;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_numeric(list, &data->idx,
-					  type, config, NULL));
+	ABORT_ON_FREE(parse_events_add_numeric(list, &data->idx,
+					  type, config, NULL), list);
 	$$ = list;
 }
 
@@ -251,7 +259,7 @@ PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5));
+	ABORT_ON_FREE(parse_events_add_cache(list, &data->idx, $1, $3, $5), list);
 	$$ = list;
 }
 |
@@ -261,7 +269,7 @@ PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL));
+	ABORT_ON_FREE(parse_events_add_cache(list, &data->idx, $1, $3, NULL), list);
 	$$ = list;
 }
 |
@@ -271,7 +279,7 @@ PE_NAME_CACHE_TYPE
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL));
+	ABORT_ON_FREE(parse_events_add_cache(list, &data->idx, $1, NULL, NULL), list);
 	$$ = list;
 }
 
@@ -282,8 +290,8 @@ PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
-					     (void *) $2, $4));
+	ABORT_ON_FREE(parse_events_add_breakpoint(list, &data->idx,
+					     (void *) $2, $4), list);
 	$$ = list;
 }
 |
@@ -293,8 +301,8 @@ PE_PREFIX_MEM PE_VALUE sep_dc
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
-					     (void *) $2, NULL));
+	ABORT_ON_FREE(parse_events_add_breakpoint(list, &data->idx,
+					     (void *) $2, NULL), list);
 	$$ = list;
 }
 
@@ -305,7 +313,7 @@ PE_NAME ':' PE_NAME
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_tracepoint(list, &data->idx, $1, $3));
+	ABORT_ON_FREE(parse_events_add_tracepoint(list, &data->idx, $1, $3), list);
 	$$ = list;
 }
 
@@ -316,7 +324,8 @@ PE_VALUE ':' PE_VALUE
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_numeric(list, &data->idx, (u32)$1, $3, NULL));
+	ABORT_ON_FREE(parse_events_add_numeric(list, &data->idx,
+					(u32)$1, $3, NULL), list);
 	$$ = list;
 }
 
@@ -327,8 +336,8 @@ PE_RAW
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_numeric(list, &data->idx,
-					  PERF_TYPE_RAW, $1, NULL));
+	ABORT_ON_FREE(parse_events_add_numeric(list, &data->idx,
+					  PERF_TYPE_RAW, $1, NULL), list);
 	$$ = list;
 }
 
-- 
1.7.10.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-07-07 20:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-07 20:43 [PATCH] perf: free list on error path parsing events David Ahern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.