diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-04-12 09:50:08 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-04-12 10:02:26 -0300 |
commit | efe98a7a39777ce266142159f303fb52c3b817c0 (patch) | |
tree | 6437f90f6114102162acf467c6b2bbdc2f11a0a9 /tools | |
parent | 9fbde6c8002bce61acd0c2187cc41c43a7c99968 (diff) | |
download | linux-stable-efe98a7a39777ce266142159f303fb52c3b817c0.tar.gz linux-stable-efe98a7a39777ce266142159f303fb52c3b817c0.tar.bz2 linux-stable-efe98a7a39777ce266142159f303fb52c3b817c0.zip |
perf pmu: 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.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/pmu.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 91cccfb3c515..01533302d5f9 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -972,8 +972,7 @@ static struct perf_pmu *pmu_lookup(int dirfd, const char *lookup_name) return pmu; err: - if (pmu->name) - free(pmu->name); + zfree(&pmu->name); free(pmu); return NULL; } @@ -1519,7 +1518,7 @@ void perf_pmu__del_formats(struct list_head *formats) list_for_each_entry_safe(fmt, tmp, formats, list) { list_del(&fmt->list); - free(fmt->name); + zfree(&fmt->name); free(fmt); } } @@ -1866,8 +1865,8 @@ static void perf_pmu__del_caps(struct perf_pmu *pmu) list_for_each_entry_safe(caps, tmp, &pmu->caps, list) { list_del(&caps->list); - free(caps->name); - free(caps->value); + zfree(&caps->name); + zfree(&caps->value); free(caps); } } @@ -2089,9 +2088,9 @@ static void perf_pmu__delete(struct perf_pmu *pmu) perf_cpu_map__put(pmu->cpus); - free(pmu->default_config); - free(pmu->name); - free(pmu->alias_name); + zfree(&pmu->default_config); + zfree(&pmu->name); + zfree(&pmu->alias_name); free(pmu); } |