Skip to contentSkip to conversation

perf pmu: Improve exception handling in perf_pmu__lookup()

PATCH New Markus Elfring 1 participant 1 message Mar 4, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf pmu: Improve exception handling in perf_pmu__lookup()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Mar 2025 12:55:05 +0100

A zfree() call is not helpful after a failed strdup(name) call in this function implementation.
Thus use an other jump target instead.

---
 tools/perf/util/pmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/pmu.c +2 -1
index 57450c73fb63..74eb46390233 100644
@@ -1107,7 +1107,7 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
 
 	pmu->name = strdup(name);
 	if (!pmu->name)
-		goto err;
+		goto free_pmu;
 
 	/*
 	 * Read type early to fail fast if a lookup name isn't a PMU. Ensure
@@ -1155,6 +1155,7 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
 	return pmu;
 err:
 	zfree(&pmu->name);
+free_pmu:
 	free(pmu);
 	return NULL;
 }

--
2.48.1