[PATCH v1 4/4] perf pmu: Free alias on error paths in perf_pmu__new_alias()

From: Ian Rogers

Date: Wed Nov 18 2026 - 02:55:47 EST


In perf_pmu__new_alias(), alias is allocated with zalloc(), but if
parse_double() fails on any of the retirement latency fields or
io__getline() fails when reading sysfs alias terms, the function returns
ret directly without freeing alias.

Call perf_pmu_free_alias(alias) on both error paths, matching the
existing perf_pmu__convert_scale() failure path.

Fixes: 84bae3af20d0 ("perf pmu: Don't eagerly parse event terms")
Fixes: fc807b6bde6a ("perf pmu-events: Add retirement latency to JSON events inside of perf")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/pmu.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 1ae8bcf..adf85d0 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -607,8 +607,10 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
ret = parse_double(pe->retirement_latency_max, NULL,
&alias->retirement_latency_max);
}
- if (ret)
+ if (ret) {
+ perf_pmu_free_alias(alias);
return ret;
+ }

if (val_fd < 0) {
alias->terms = strdup(val);
@@ -621,6 +623,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
ret = io__getline(&io, &alias->terms, &line_len) < 0 ? -errno : 0;
if (ret) {
pr_err("Failed to read alias %s\n", name);
+ perf_pmu_free_alias(alias);
return ret;
}
if (line_len >= 1 && alias->terms[line_len - 1] == '\n')
--
2.56.1.703.gf848ed807c-goog