[PATCH v4 1/7] perf machine: Fix leak when creating host kernel maps fails
From: Ian Rogers
Date: Fri Dec 04 2026 - 15:59:11 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.
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;
--
2.56.1.915.g69d5ec7298-goog