[PATCH 01/54] perf tools: Fix dangling pointers in parse_events__free_terms

From: Wang Nan
Date: Fri Feb 05 2016 - 09:20:47 EST


We expect parse_events__free_terms() destory the full config term list.
However, current code leaves the list header unclean, and points to
a invalidated linked list.

Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
Cc: He Kuang <hekuang@xxxxxxxxxx>
Cc: Alexei Starovoitov <ast@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Zefan Li <lizefan@xxxxxxxxxx>
Cc: pi3orama@xxxxxxx
---
tools/perf/util/parse-events.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 813d9b2..e8b2d85 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2072,8 +2072,15 @@ void parse_events__free_terms(struct list_head *terms)
{
struct parse_events_term *term, *h;

- list_for_each_entry_safe(term, h, terms, list)
+ if (!terms)
+ return;
+
+ list_for_each_entry_safe(term, h, terms, list) {
+ list_del(&term->list);
free(term);
+ }
+
+ free(terms);
}

void parse_events_evlist_error(struct parse_events_evlist *data,
--
1.8.3.4