[PATCH 1/6] perf machine: Fix leak when creating host kernel maps fails
From: Ian Rogers
Date: Thu Dec 03 2026 - 20:05:16 EST
If machine__create_kernel_maps() fails in __machine__new_host() the
machine is freed with free(), leaking what machine__init() and the
partially created kernel maps allocated, such as the kmaps, root_dir,
mmap_name, kernel DSO and threads. Use machine__delete() to release
them.
Fixes: 8fb598e5a3b0 ("perf trace: Fix comm resolution when reading events from file")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
Notes:
The leak was found by the Sashiko AI review tool when reviewing an
earlier version of this series.
This change was developed with the help of an AI coding assistant
(Gemini in Jetski), which wrote the initial code, tests and
changelog; it was reviewed, built and tested by the author.
tools/perf/util/machine.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 2750d507aecc..5fbc5941a2bc 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -144,7 +144,7 @@ static struct machine *__machine__new_host(struct perf_env *host_env, bool kerne
}
if (kernel_maps && machine__create_kernel_maps(machine) < 0) {
- free(machine);
+ machine__delete(machine);
return NULL;
}
machine->env = host_env;
base-commit: 22f7d78dc87e43ff4f7c03d23f46f49692c41ad0
--
2.56.1.915.g69d5ec7298-goog