From: Ian Rogers Date: Thu, 22 Jan 2026 21:35:05 +0000 (-0800) Subject: perf header: Fix memory leaks in process_cpu_domain_info() X-Git-Tag: v7.0-rc1~16^2~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d84f24c898864facc13412a58b78964f6a769d76;p=thirdparty%2Flinux.git perf header: Fix memory leaks in process_cpu_domain_info() do_read_string() returns a string in allocated memory, for some reason there was unused memory allocations and unnecessary strdups. Remove these and make the "perf annotate basic tests" leak sanitizer clean. Fixes: d40c68a49f69c9bd ("perf header: Support CPU DOMAIN relation info") Reviewed-by: James Clark Signed-off-by: Ian Rogers Cc: Aditya Bodkhe Cc: Adrian Hunter Cc: Albert Ou Cc: Alexander Shishkin Cc: Alexandre Ghiti Cc: Athira Rajeev Cc: Bill Wendling Cc: Dr. David Alan Gilbert Cc: Guo Ren Cc: Howard Chu Cc: Ingo Molnar Cc: Jiri Olsa Cc: John Garry Cc: Julia Lawall Cc: Justin Stitt Cc: Krzysztof Ɓopatowski Cc: Leo Yan Cc: linux-arm-kernel@lists.infradead.org Cc: linux-csky@vger.kernel.org Cc: linux-riscv@lists.infradead.org Cc: Namhyung Kim Cc: Nathan Chancellor Cc: Nick Desaulniers Cc: Palmer Dabbelt Cc: Paul Walmsley Cc: Peter Zijlstra Cc: Sergei Trofimovich Cc: Shimin Guo Cc: Suchit Karunakaran Cc: Swapnil Sapkal Cc: Thomas Falcon Cc: Tianyou Li Cc: Will Deacon Cc: Zecheng Li Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 9a15dd4b7640..eefd1cd73b6a 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3634,6 +3634,7 @@ static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_unused if (!d_info) return -1; + assert(cd_map[cpu]->domains[domain] == NULL); cd_map[cpu]->domains[domain] = d_info; d_info->domain = domain; @@ -3642,30 +3643,20 @@ static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_unused if (!dname) return -1; - d_info->dname = zalloc(strlen(dname) + 1); - if (!d_info->dname) - return -1; - - d_info->dname = strdup(dname); + d_info->dname = dname; } cpumask = do_read_string(ff); if (!cpumask) return -1; - d_info->cpumask = zalloc(strlen(cpumask) + 1); - if (!d_info->cpumask) - return -1; - d_info->cpumask = strdup(cpumask); + d_info->cpumask = cpumask; cpulist = do_read_string(ff); if (!cpulist) return -1; - d_info->cpulist = zalloc(strlen(cpulist) + 1); - if (!d_info->cpulist) - return -1; - d_info->cpulist = strdup(cpulist); + d_info->cpulist = cpulist; } }