Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tanushree Shah" <tshah@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf data convert json: Fix trace_seq memory leak in process_sample_event()
Date: Thu, 04 Jun 2026 07:06:16 +0000	[thread overview]
Message-ID: <20260604070617.0050E1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604065519.112101-1-tshah@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The `process_sample_event()` function leaks reference counts and memory associated with `struct addr_location` when a sample is skipped due to time filtering.
--

commit de6e4710063f2942dd58ebe436d7d992872132b3
Author: Tanushree Shah <tshah@linux.ibm.com>

perf data convert json: Fix trace_seq memory leak in process_sample_event()

This commit fixes a memory leak by ensuring trace_seq_destroy() is called
to pair with trace_seq_init() when formatting tracepoint raw data.

> diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
> index d526c91312ed8..6dd9349ab10f1 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++;
>  			}

[Severity: High]
This is a pre-existing issue, but does the early return path for skipped
samples higher up in process_sample_event() leak the addr_location
reference handles?

tools/perf/util/data-convert-json.c:process_sample_event() {
        addr_location__init(&al);
        if (machine__resolve(machine, &al, sample) < 0) {
                pr_err("Sample resolution failed!\n");
                addr_location__exit(&al);
                return -1;
        }

        if (perf_time__ranges_skip_sample(c->ptime_range, c->range_num, sample->time)) {
                ++c->skipped;
                return 0;
        }
        ...
}

When machine__resolve() populates the addr_location structure, it acquires
reference handles for objects like thread and map. The early return for time
filtering bypasses the addr_location__exit() cleanup.

Could this cause reference counts and memory to leak when dropping skipped
samples?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260604065519.112101-1-tshah@linux.ibm.com?part=1

  reply	other threads:[~2026-06-04  7:06 UTC|newest]

Thread overview: 4+ 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  7:06 ` sashiko-bot [this message]
2026-06-04 16:10   ` Tanushree Shah
2026-06-04 21:29 ` 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=20260604070617.0050E1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tshah@linux.ibm.com \
    /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