Commit 360e071b authored by Taeung Song's avatar Taeung Song Committed by Arnaldo Carvalho de Melo

perf tools: Use zfree() to avoid keeping dangling pointers

The cases changed in this patch are for when we free but keep the
pointer to the freed area, which is not always a good idea.

Be more defensive and zero the pointer to avoid possible use after
free bugs to take more time to be detected.
Signed-off-by: default avatarTaeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1485952447-7013-5-git-send-email-treeze.taeung@gmail.com
[ rewrote commit log ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 506fde11
...@@ -1479,7 +1479,7 @@ static void perf_pmu__parse_cleanup(void) ...@@ -1479,7 +1479,7 @@ static void perf_pmu__parse_cleanup(void)
for (i = 0; i < perf_pmu_events_list_num; i++) { for (i = 0; i < perf_pmu_events_list_num; i++) {
p = perf_pmu_events_list + i; p = perf_pmu_events_list + i;
free(p->symbol); zfree(&p->symbol);
} }
zfree(&perf_pmu_events_list); zfree(&perf_pmu_events_list);
perf_pmu_events_list_num = 0; perf_pmu_events_list_num = 0;
...@@ -1570,7 +1570,7 @@ perf_pmu__parse_check(const char *name) ...@@ -1570,7 +1570,7 @@ perf_pmu__parse_check(const char *name)
r = bsearch(&p, perf_pmu_events_list, r = bsearch(&p, perf_pmu_events_list,
(size_t) perf_pmu_events_list_num, (size_t) perf_pmu_events_list_num,
sizeof(struct perf_pmu_event_symbol), comp_pmu); sizeof(struct perf_pmu_event_symbol), comp_pmu);
free(p.symbol); zfree(&p.symbol);
return r ? r->type : PMU_EVENT_SYMBOL_ERR; return r ? r->type : PMU_EVENT_SYMBOL_ERR;
} }
...@@ -1717,8 +1717,8 @@ static void parse_events_print_error(struct parse_events_error *err, ...@@ -1717,8 +1717,8 @@ static void parse_events_print_error(struct parse_events_error *err,
fprintf(stderr, "%*s\\___ %s\n", idx + 1, "", err->str); fprintf(stderr, "%*s\\___ %s\n", idx + 1, "", err->str);
if (err->help) if (err->help)
fprintf(stderr, "\n%s\n", err->help); fprintf(stderr, "\n%s\n", err->help);
free(err->str); zfree(&err->str);
free(err->help); zfree(&err->help);
} }
fprintf(stderr, "Run 'perf list' for a list of valid events\n"); fprintf(stderr, "Run 'perf list' for a list of valid events\n");
...@@ -2413,7 +2413,7 @@ void parse_events_terms__purge(struct list_head *terms) ...@@ -2413,7 +2413,7 @@ void parse_events_terms__purge(struct list_head *terms)
list_for_each_entry_safe(term, h, terms, list) { list_for_each_entry_safe(term, h, terms, list) {
if (term->array.nr_ranges) if (term->array.nr_ranges)
free(term->array.ranges); zfree(&term->array.ranges);
list_del_init(&term->list); list_del_init(&term->list);
free(term); free(term);
} }
...@@ -2429,7 +2429,7 @@ void parse_events_terms__delete(struct list_head *terms) ...@@ -2429,7 +2429,7 @@ void parse_events_terms__delete(struct list_head *terms)
void parse_events__clear_array(struct parse_events_array *a) void parse_events__clear_array(struct parse_events_array *a)
{ {
free(a->ranges); zfree(&a->ranges);
} }
void parse_events_evlist_error(struct parse_events_evlist *data, void parse_events_evlist_error(struct parse_events_evlist *data,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment