From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@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 20:21:49 -0300 [thread overview]
Message-ID: <aiNaDclowc8qm2Qs@x1> (raw)
In-Reply-To: <20260605231155.2415760-2-namhyung@kernel.org>
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.
> + 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:21 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 [this message]
2026-06-05 23:31 ` Namhyung Kim
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=aiNaDclowc8qm2Qs@x1 \
--to=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=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.