public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: acme@ghostprotocols.net, linux-kernel@vger.kernel.org
Cc: David Ahern <dsahern@gmail.com>, Ingo Molnar <mingo@kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>
Subject: [PATCH] perf: free list on error path parsing events
Date: Sun,  7 Jul 2013 14:43:04 -0600	[thread overview]
Message-ID: <1373229784-6078-1-git-send-email-dsahern@gmail.com> (raw)

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


                 reply	other threads:[~2013-07-07 20:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373229784-6078-1-git-send-email-dsahern@gmail.com \
    --to=dsahern@gmail.com \
    --cc=acme@ghostprotocols.net \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox