5f48cb6 moved list memory allocations into parse-events.y. That memory needs to be freed on a parse failure.
Reported-by: Jiri Olsa <[email protected]> Signed-off-by: David Ahern <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/

