Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf pmu: Fix a potential memory leak in perf_pmu__lookup()

The commit in Fixes has reordered some code, but missed an error handling
path.

'goto err' now, in order to avoid a memory leak in case of error.

Fixes: f63a536f03a2 ("perf pmu: Merge JSON events with sysfs at load time")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Ian Rogers <irogers@google.com>
Cc: kernel-janitors@vger.kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/9538b2b634894c33168dfe9d848d4df31fd4d801.1693085544.git.christophe.jaillet@wanadoo.fr

authored by

Christophe JAILLET and committed by
Namhyung Kim
ef5de161 eb94225e

+3 -4
+3 -4
tools/perf/util/pmu.c
··· 1022 1022 * type value and format definitions. Load both right 1023 1023 * now. 1024 1024 */ 1025 - if (pmu_format(pmu, dirfd, name)) { 1026 - free(pmu); 1027 - return NULL; 1028 - } 1025 + if (pmu_format(pmu, dirfd, name)) 1026 + goto err; 1027 + 1029 1028 pmu->is_core = is_pmu_core(name); 1030 1029 pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core); 1031 1030