perf evsel: Use zfree() to reduce chances of use after free

Do defensive programming by using zfree() to initialize freed pointers
to NULL, so that eventual use after free result in a NULL pointer deref
instead of more subtle behaviour.

Also remove one NULL test before free(), as it accepts a NULL arg and we
get one line shaved not doing it explicitely.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent efe98a7a
...@@ -2917,7 +2917,6 @@ bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize) ...@@ -2917,7 +2917,6 @@ bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize)
if (asprintf(&new_name, "%s%su", name, sep) < 0) if (asprintf(&new_name, "%s%su", name, sep) < 0)
return false; return false;
if (evsel->name)
free(evsel->name); free(evsel->name);
evsel->name = new_name; evsel->name = new_name;
scnprintf(msg, msgsize, "kernel.perf_event_paranoid=%d, trying " scnprintf(msg, msgsize, "kernel.perf_event_paranoid=%d, trying "
...@@ -3156,7 +3155,7 @@ void evsel__zero_per_pkg(struct evsel *evsel) ...@@ -3156,7 +3155,7 @@ void evsel__zero_per_pkg(struct evsel *evsel)
if (evsel->per_pkg_mask) { if (evsel->per_pkg_mask) {
hashmap__for_each_entry(evsel->per_pkg_mask, cur, bkt) hashmap__for_each_entry(evsel->per_pkg_mask, cur, bkt)
free((void *)cur->pkey); zfree(&cur->pkey);
hashmap__clear(evsel->per_pkg_mask); hashmap__clear(evsel->per_pkg_mask);
} }
......
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