diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-04-12 14:50:08 +0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-04-12 15:03:37 +0200 |
commit | cdf13c0918c9b1b233d6db690fc4c06afbc29e57 (patch) | |
tree | 69ca3b661930913dc36e264523dbea6cf3464928 | |
parent | perf pmu: Use zfree() to reduce chances of use after free (diff) | |
download | linux-cdf13c0918c9b1b233d6db690fc4c06afbc29e57.tar.xz linux-cdf13c0918c9b1b233d6db690fc4c06afbc29e57.zip |
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: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/evsel.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index fe3ce765a4f3..a85a987128aa 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2917,8 +2917,7 @@ bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize) if (asprintf(&new_name, "%s%su", name, sep) < 0) return false; - if (evsel->name) - free(evsel->name); + free(evsel->name); evsel->name = new_name; scnprintf(msg, msgsize, "kernel.perf_event_paranoid=%d, trying " "to fall back to excluding kernel and hypervisor " @@ -3156,7 +3155,7 @@ void evsel__zero_per_pkg(struct evsel *evsel) if (evsel->per_pkg_mask) { hashmap__for_each_entry(evsel->per_pkg_mask, cur, bkt) - free((void *)cur->pkey); + zfree(&cur->pkey); hashmap__clear(evsel->per_pkg_mask); } |