All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>,
	Ian Rogers <irogers@google.com>,
	 linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/4] perf pmu: Free alias on error paths in perf_pmu__new_alias()
Date: Mon, 30 Nov 2026 14:43:32 -0800	[thread overview]
Message-ID: <20261130224332.79575-5-irogers@google.com> (raw)
In-Reply-To: <20261130224332.79575-1-irogers@google.com>

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@google.com>
---
 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 1ae8bcf71c68..adf85d0c26c2 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.839.g22a8290db9-goog


  parent reply	other threads:[~2026-11-30 22:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 22:43 [PATCH v2 0/4] perf tools: Fix thread cache race, stat per-pkg delta bug, and memory leaks Ian Rogers
2026-11-30 22:43 ` [PATCH v2 1/4] perf threads: Don't resurrect removed threads in last_match Ian Rogers
2026-11-30 22:43 ` [PATCH v2 2/4] perf stat: Skip per-pkg secondary CPUs after computing deltas Ian Rogers
2026-11-30 22:43 ` [PATCH v2 3/4] perf metricgroup: Fix realloc() leaks in resolve_metric() and __add_metric() Ian Rogers
2026-11-30 22:43 ` Ian Rogers [this message]
2026-11-30 22:53 ` [PATCH v2 0/4] perf tools: Fix thread cache race, stat per-pkg delta bug, and memory leaks sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130224332.79575-5-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.