perf pmu: Fix a potential memory leak in perf_pmu__lookup()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 26 Aug 2023 21:32:45 +0000 (23:32 +0200)
committerNamhyung Kim <namhyung@kernel.org>
Tue, 27 Feb 2024 05:43:00 +0000 (21:43 -0800)
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
tools/perf/util/pmu.c

index 437386dedd5c005897179b8d74901ffad4f68e5b..f39cbbc1a7ec1dcecd9052f917400a3596939363 100644 (file)
@@ -1022,10 +1022,9 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
         * type value and format definitions. Load both right
         * now.
         */
-       if (pmu_format(pmu, dirfd, name)) {
-               free(pmu);
-               return NULL;
-       }
+       if (pmu_format(pmu, dirfd, name))
+               goto err;
+
        pmu->is_core = is_pmu_core(name);
        pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core);