From: sashiko-bot@kernel.org
To: "Aaron Tomlin" <atomlin@atomlin.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH perf-tools-next v2 1/4] perf ftrace: Optimise __cmd_ftrace() stack frame with strbuf streaming
Date: Tue, 06 Oct 2026 23:35:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-162513@kernel.org> (raw)
In-Reply-To: <20261006232756.65620-2-atomlin@atomlin.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: Memory leak of buf and linebuf on early ftrace setup error paths
--
commit e5886f5c4e0cc584a5a7ac05c7c069ab1b80f135
Author: Aaron Tomlin <atomlin@atomlin.com>
perf ftrace: Optimise __cmd_ftrace() stack frame with strbuf streaming
This commit refactors __cmd_ftrace() to use a dynamically allocated buffer
and a string buffer for streaming trace data instead of a fixed stack array.
> diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> index 6017493ff1797..4e77a0b2513f8 100644
> --- a/tools/perf/builtin-ftrace.c
> +++ b/tools/perf/builtin-ftrace.c
[ ... ]
> @@ -767,6 +771,13 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace)
>
> setup_pager();
>
> + buf = malloc(TRACE_BUF_SIZE);
> + if (!buf) {
> + pr_err("failed to allocate trace buffer\n");
> + goto out_reset;
> + }
> + strbuf_init(&linebuf, 512);
> +
> trace_file = get_tracing_instance_file("trace_pipe");
> if (!trace_file) {
> pr_err("failed to open trace_pipe\n");
[Severity: Medium]
If get_tracing_instance_file("trace_pipe") returns NULL, or if the subsequent
open(trace_file, O_RDONLY) fails within __cmd_ftrace() in
tools/perf/builtin-ftrace.c, the error path executes goto out_reset.
Because the out_reset label completely skips the resource teardown label
out_close_fd:
out_close_fd:
free(buf);
strbuf_release(&linebuf);
close(trace_fd);
out_reset:
exit_tracing_instance();
Does this permanently leak the heap-allocated buf (TRACE_BUF_SIZE bytes) and
the internal buffer of linebuf on these early ftrace setup error paths?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261006232756.65620-1-atomlin@atomlin.com?part=1
next prev parent reply other threads:[~2026-10-06 23:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 23:27 [PATCH perf-tools-next v2 0/4] perf ftrace: Support inlined functions and display enhancements in function graph tracer Aaron Tomlin
2026-10-06 23:27 ` [PATCH perf-tools-next v2 1/4] perf ftrace: Optimise __cmd_ftrace() stack frame with strbuf streaming Aaron Tomlin
2026-10-06 23:35 ` sashiko-bot [this message]
2026-10-07 15:46 ` Aaron Tomlin
2026-10-06 23:27 ` [PATCH perf-tools-next v2 2/4] perf ftrace: Support filtering return address comments Aaron Tomlin
2026-10-06 23:37 ` sashiko-bot
2026-10-07 16:04 ` Aaron Tomlin
2026-10-06 23:27 ` [PATCH perf-tools-next v2 3/4] perf ftrace: Support display of inlined functions in function graph tracer Aaron Tomlin
2026-10-06 23:40 ` sashiko-bot
2026-10-06 23:27 ` [PATCH perf-tools-next v2 4/4] perf ftrace: Support omitting execution duration " Aaron Tomlin
2026-10-06 23:35 ` sashiko-bot
2026-10-07 23:24 ` [PATCH perf-tools-next v2 0/4] perf ftrace: Support inlined functions and display enhancements " Namhyung Kim
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=sashiko-outbox-162513@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=atomlin@atomlin.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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