Linux Perf Users
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	mingo@redhat.com,  acme@kernel.org, namhyung@kernel.org,
	jolsa@kernel.org,  adrian.hunter@intel.com,
	james.clark@linaro.org, dsahern@gmail.com,  andrii@kernel.org,
	Ian Rogers <irogers@google.com>
Subject: [PATCH v4 1/7] perf machine: Fix leak when creating host kernel maps fails
Date: Fri,  4 Dec 2026 12:58:47 -0800	[thread overview]
Message-ID: <20261204205854.3973609-2-irogers@google.com> (raw)
In-Reply-To: <20261204205854.3973609-1-irogers@google.com>

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@google.com>
---

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


  reply	other threads:[~2026-12-04 20:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 20:58 [PATCH v4 0/7] perf synthetic-events: Use PROCMAP_QUERY for mmap synthesis Ian Rogers
2026-12-04 20:58 ` Ian Rogers [this message]
2026-12-04 20:58 ` [PATCH v4 2/7] perf synthetic-events: Fix race on DSO build IDs when synthesizing Ian Rogers
2026-12-04 20:58 ` [PATCH v4 3/7] perf bench synthesize: Initialize symbols so build IDs can be read Ian Rogers
2026-12-04 20:58 ` [PATCH v4 4/7] tools headers UAPI: Synchronize linux/fs.h with the kernel sources Ian Rogers
2026-12-04 20:58 ` [PATCH v4 5/7] perf synthetic-events: Use PROCMAP_QUERY to synthesize mmap events Ian Rogers
2026-12-04 20:58 ` [PATCH v4 6/7] perf bench synthesize: Add --procmap-query option Ian Rogers
2026-12-04 20:58 ` [PATCH v4 7/7] perf test: Add test comparing PROCMAP_QUERY and /proc/pid/maps synthesis Ian Rogers
2026-12-04 21:16   ` sashiko-bot
2026-12-04 21:16 ` [PATCH v4 0/7] perf synthetic-events: Use PROCMAP_QUERY for mmap synthesis sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204205854.3973609-2-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=andrii@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox