From: Ian Rogers <irogers@google.com>
To: Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Alireza Haghdoost <haghdoost@uber.com>,
Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v8 01/10] perf kmem: Fix alloc_func_regex leak on error in build_alloc_func_list()
Date: Sat, 21 Nov 2026 21:03:56 -0800 [thread overview]
Message-ID: <20261122050405.80335-2-irogers@google.com> (raw)
In-Reply-To: <20261122050405.80335-1-irogers@google.com>
In build_alloc_func_list(), after regcomp(&alloc_func_regex, ...)
succeeds, the early error returns on map__load() failure and realloc()
failure return without calling regfree(&alloc_func_regex), leaking the
compiled regular expression buffer.
Call regfree(&alloc_func_regex) on both error paths before returning.
Fixes: c9758cc45699 ("perf kmem: Implement stat --page --caller")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/builtin-kmem.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 8693c6b135ca..1404b523a785 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -364,6 +364,7 @@ static int build_alloc_func_list(void)
kernel_map = machine__kernel_map(machine);
if (map__load(kernel_map) < 0) {
pr_err("cannot load kernel map\n");
+ regfree(&alloc_func_regex);
return -ENOENT;
}
@@ -373,8 +374,10 @@ static int build_alloc_func_list(void)
func = realloc(alloc_func_list,
(nr_alloc_funcs + 1) * sizeof(*func));
- if (func == NULL)
+ if (func == NULL) {
+ regfree(&alloc_func_regex);
return -ENOMEM;
+ }
pr_debug("alloc func: %s\n", sym->name);
func[nr_alloc_funcs].start = sym->start;
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-22 5:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 5:03 [PATCH v8 00/10] perf symbol: Sorted arrays, DSO-owned lifetimes, and memory shrinking Ian Rogers
2026-11-22 5:03 ` Ian Rogers [this message]
2026-11-22 5:03 ` [PATCH v8 02/10] perf maps: Add tail fast-path check in first_ending_after() Ian Rogers
2026-11-22 5:03 ` [PATCH v8 03/10] perf symbol: Convert map__for_each_symbol() to callback-based iteration Ian Rogers
2026-11-22 5:03 ` [PATCH v8 04/10] perf symbol: Use callback iteration instead of open-coded symbol loops Ian Rogers
2026-11-22 5:04 ` [PATCH v8 05/10] perf symbol: Switch backing storage from rbtree to struct symbols array Ian Rogers
2026-11-22 5:04 ` [PATCH v8 06/10] perf symbol: Replace qsort() with natural-run merge sort Ian Rogers
2026-11-22 5:04 ` [PATCH v8 07/10] perf symbol: Optimize incremental symbol insertion with sorted tail Ian Rogers
2026-11-22 5:04 ` [PATCH v8 08/10] perf symbol: Add memory shrinking for symbols, DSOs, and machines Ian Rogers
2026-11-22 5:04 ` [PATCH v8 09/10] perf session: Add dso__session() and session-scoped allocation wrappers Ian Rogers
2026-11-22 5:04 ` [PATCH v8 10/10] perf test symbols: Add tests for symbol shrinking and session alloc wrappers Ian Rogers
2026-11-22 5:22 ` [PATCH v8 00/10] perf symbol: Sorted arrays, DSO-owned lifetimes, and memory shrinking sashiko-bot
2026-11-23 21:46 ` Namhyung Kim
2026-11-23 23:40 ` Ian Rogers
2026-11-24 0:31 ` Alireza Haghdoost
2026-11-24 3:27 ` Ian Rogers
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=20261122050405.80335-2-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=haghdoost@uber.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.