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


  reply	other threads:[~2026-12-04  1:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  1:04 [PATCH 0/6] perf synthetic-events: Use PROCMAP_QUERY for mmap synthesis Ian Rogers
2026-12-04  1:04 ` Ian Rogers [this message]
2026-12-04  1:04 ` [PATCH 2/6] perf synthetic-events: Fix race on DSO build IDs when synthesizing Ian Rogers
2026-12-04  1:04 ` [PATCH 3/6] perf bench synthesize: Initialize symbols so build IDs can be read Ian Rogers
2026-12-04  1:04 ` [PATCH 4/6] perf synthetic-events: Use PROCMAP_QUERY to synthesize mmap events Ian Rogers
2026-12-04  1:25   ` sashiko-bot
2026-12-04  1:04 ` [PATCH 5/6] perf bench synthesize: Add --procmap-query option Ian Rogers
2026-12-04  1:04 ` [PATCH 6/6] perf test: Add test comparing PROCMAP_QUERY and /proc/pid/maps synthesis Ian Rogers
2026-12-04  1:25 ` [PATCH 0/6] 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=20261204010452.1937224-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