From: Arnaldo Carvalho de Melo <acme@kernel•org>
To: Tanushree Shah <tshah@linux•ibm.com>
Cc: jolsa@kernel•org, adrian.hunter@intel•com, vmolnaro@redhat•com,
mpetlan@redhat•com, tmricht@linux•ibm.com, maddy@linux•ibm.com,
irogers@google•com, namhyung@kernel•org,
linux-perf-users@vger•kernel.org, linuxppc-dev@lists•ozlabs.org,
atrajeev@linux•ibm.com, hbathini@linux•ibm.com,
Tejas.Manhas1@ibm•com, Tanushree.Shah@ibm•com,
Shivani.Nittor@ibm•com
Subject: Re: [PATCH] perf data convert json: Fix trace_seq memory leak in process_sample_event()
Date: Thu, 4 Jun 2026 18:29:04 -0300 [thread overview]
Message-ID: <aiHuIBAIgv3L6TI7@x1> (raw)
In-Reply-To: <20260604065519.112101-1-tshah@linux.ibm.com>
On Thu, Jun 04, 2026 at 12:25:19PM +0530, Tanushree Shah wrote:
> Unlike the in-kernel trace_seq which uses a statically allocated buffer,
> the userspace traceevent library's trace_seq uses a dynamically allocated
> one. Therefore, every trace_seq_init() call must be paired with a
> trace_seq_destroy(), otherwise it produces a memory leak.
>
> In process_sample_event(), a trace_seq is initialized for each field when
> formatting tracepoint raw_data, but the matching trace_seq_destroy() is
> never called, leaking memory for every field of every sample processed.
>
> Add the missing trace_seq_destroy() after using the trace_seq buffer to
> properly free the allocated memory.
>
> Detected with Valgrind on a perf.data file with 2,729 tracepoint samples:
> Before: definitely lost: 55,537,664 bytes in 13,559 blocks
> After: definitely lost: 0 bytes in 0 blocks
Thanks, applied to perf-tools-next, for v7.2.
- Arnaldo
> Fixes: 9d895e468429 ("perf data: Add tracepoint fields when converting to JSON")
> Signed-off-by: Tanushree Shah <tshah@linux•ibm.com>
> ---
> tools/perf/util/data-convert-json.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
> index d526c91312ed..6dd9349ab10f 100644
> --- a/tools/perf/util/data-convert-json.c
> +++ b/tools/perf/util/data-convert-json.c
> @@ -257,6 +257,7 @@ static int process_sample_event(const struct perf_tool *tool,
> trace_seq_init(&s);
> tep_print_field(&s, sample->raw_data, fields[i]);
> output_json_key_string(out, true, 3, fields[i]->name, s.buffer);
> + trace_seq_destroy(&s);
>
> i++;
> }
> --
> 2.47.3
prev parent reply other threads:[~2026-06-04 21:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 6:55 [PATCH] perf data convert json: Fix trace_seq memory leak in process_sample_event() Tanushree Shah
2026-06-04 21:29 ` Arnaldo Carvalho de Melo [this message]
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=aiHuIBAIgv3L6TI7@x1 \
--to=acme@kernel$(echo .)org \
--cc=Shivani.Nittor@ibm$(echo .)com \
--cc=Tanushree.Shah@ibm$(echo .)com \
--cc=Tejas.Manhas1@ibm$(echo .)com \
--cc=adrian.hunter@intel$(echo .)com \
--cc=atrajeev@linux$(echo .)ibm.com \
--cc=hbathini@linux$(echo .)ibm.com \
--cc=irogers@google$(echo .)com \
--cc=jolsa@kernel$(echo .)org \
--cc=linux-perf-users@vger$(echo .)kernel.org \
--cc=linuxppc-dev@lists$(echo .)ozlabs.org \
--cc=maddy@linux$(echo .)ibm.com \
--cc=mpetlan@redhat$(echo .)com \
--cc=namhyung@kernel$(echo .)org \
--cc=tmricht@linux$(echo .)ibm.com \
--cc=tshah@linux$(echo .)ibm.com \
--cc=vmolnaro@redhat$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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