From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 1/4] perf timechart: Release event samples at the end
Date: Fri, 5 Jun 2026 16:31:32 -0700 [thread overview]
Message-ID: <aiNcVPMpx-WJYukY@google.com> (raw)
In-Reply-To: <aiNaDclowc8qm2Qs@x1>
On Fri, Jun 05, 2026 at 08:21:49PM -0300, Arnaldo Carvalho de Melo wrote:
> On Fri, Jun 05, 2026 at 04:11:52PM -0700, Namhyung Kim wrote:
> > Add timechart__release() to free all data structures added during the
> > sample processing.
> >
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > ---
> > tools/perf/builtin-timechart.c | 54 ++++++++++++++++++++++++++++++++++
> > 1 file changed, 54 insertions(+)
> >
> > diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
> > index 04dbb944a42720b4..7c4ace51302e260c 100644
> > --- a/tools/perf/builtin-timechart.c
> > +++ b/tools/perf/builtin-timechart.c
> > @@ -1548,6 +1548,59 @@ static void write_svg_file(struct timechart *tchart, const char *filename)
> > svg_close();
> > }
> >
> > +static void timechart__release(struct timechart *tchart)
> > +{
> > + struct per_pid *p = tchart->all_data;
> > + struct power_event *pwr = tchart->power_events;
> > + struct wake_event *we = tchart->wake_events;
> > +
> > + while (p) {
> > + struct per_pid *next_pid = p->next;
> > + struct per_pidcomm *c = p->all;
> > +
> > + while (c) {
> > + struct per_pidcomm *next_comm = c->next;
> > + struct cpu_sample *cs = c->samples;
> > + struct io_sample *ios = c->io_samples;
> > +
> > + while (cs) {
> > + struct cpu_sample *next = cs->next;
> > +
> > + free((char *)cs->backtrace);
>
> zfree()? This way if somebody has a
> pointer to cs and tries to use
> cs->backtrace after this free, it will
> segfault instead of using garbage or
> worse, setting some other unrelated
> struct to some cpu_sample field supposed
> value.
Ok, will do here and others below.
Thanks,
Namhyung
>
> > + free(cs);
> > + cs = next;
> > + }
> > +
> > + while (ios) {
> > + struct io_sample *next = ios->next;
> > +
> > + free(ios);
>
> io->next = NULL;
>
> > + ios = next;
> > + }
> > +
> > + free(c->comm);
>
> zfree
>
> > + free(c);
> > + c = next_comm;
> > + }
> > + p = next_pid;
> > + }
> > +
> > + while (pwr) {
> > + struct power_event *next = pwr->next;
> > +
> > + free(pwr);
> pwr->next = NULL;
> > + pwr = next;
> > + }
> > +
> > + while (we) {
> > + struct wake_event *next = we->next;
> > +
> > + free((char *)we->backtrace);
> zfree
> > + free(we);
> > + we = next;
> > + }
> > +}
> > +
> > static int process_header(struct perf_file_section *section __maybe_unused,
> > struct perf_header *ph,
> > int feat,
> > @@ -2079,6 +2132,7 @@ int cmd_timechart(int argc, const char **argv)
> >
> > ret = __cmd_timechart(&tchart, output_name);
> > out:
> > + timechart__release(&tchart);
> > zfree(&cpus_cstate_start_times);
> > zfree(&cpus_cstate_state);
> > zfree(&cpus_pstate_start_times);
> > --
> > 2.54.0.1032.g2f8565e1d1-goog
next prev parent reply other threads:[~2026-06-05 23:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 23:11 [PATCH 0/4] perf timechart: Fix memory leaks Namhyung Kim
2026-06-05 23:11 ` [PATCH 1/4] perf timechart: Release event samples at the end Namhyung Kim
2026-06-05 23:21 ` Arnaldo Carvalho de Melo
2026-06-05 23:31 ` Namhyung Kim [this message]
2026-06-05 23:23 ` sashiko-bot
2026-06-05 23:32 ` Namhyung Kim
2026-06-05 23:11 ` [PATCH 2/4] perf timechart: Fix memory leaks during record Namhyung Kim
2026-06-05 23:21 ` sashiko-bot
2026-06-05 23:23 ` Arnaldo Carvalho de Melo
2026-06-05 23:11 ` [PATCH 3/4] perf timechart: Fix memory leaks in draw_wakeups() Namhyung Kim
2026-06-05 23:17 ` sashiko-bot
2026-06-05 23:20 ` Namhyung Kim
2026-06-05 23:11 ` [PATCH 4/4] perf test: Update perf timechart test Namhyung Kim
2026-06-05 23:19 ` [PATCH 0/4] perf timechart: Fix memory leaks Arnaldo Carvalho de Melo
2026-06-05 23:28 ` Namhyung Kim
2026-06-05 23:41 ` Arnaldo Carvalho de Melo
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=aiNcVPMpx-WJYukY@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.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@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