Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gu Bin" <gubin@cmss.chinamobile.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf trace: free intlist on filter_pids calloc failure
Date: Thu, 12 Nov 2026 08:42:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-210765@kernel.org> (raw)
In-Reply-To: <20261112083123.2154-1-gubin@cmss.chinamobile.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Medium] perf trace: memory leak in trace__exit() [1]
--

commit e8d1d018ef3c0a4fdf8d8ce3c0227b4280b491f6
Author: Gu Bin <gubin@cmss.chinamobile.com>

perf trace: free intlist on filter_pids calloc failure

This commit restructures trace__set_filter_pids_from_option() so that the
temporary intlist is freed even when allocating trace->filter_pids.entries
fails.

> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index 4094141461f91..d435b35f1351c 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -5432,17 +5432,16 @@ static int trace__set_filter_pids_from_option(const struct option *opt, const ch
>  	i = trace->filter_pids.nr = intlist__nr_entries(list) + 1;
>  	trace->filter_pids.entries = calloc(i, sizeof(pid_t));
>  
> -	if (trace->filter_pids.entries == NULL)
> -		goto out;
> +	if (trace->filter_pids.entries) {
> +		trace->filter_pids.entries[0] = getpid();
>  
> -	trace->filter_pids.entries[0] = getpid();
> +		for (i = 1; i < trace->filter_pids.nr; ++i)
> +			trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
>  
> -	for (i = 1; i < trace->filter_pids.nr; ++i)
> -		trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
> +		ret = 0;
> +	}

[Severity: Medium]
This problem wasn't introduced by this patch, but does trace__exit() leak
trace->filter_pids.entries [1]?  trace__set_filter_pids_from_option()
allocates the array with calloc(), and trace__exit() never frees it on
teardown.

[1] https://sashiko.dev/#/bug/linux-ae3f475f-4084-473d-a5c5-25fd465ce61d

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261112083123.2154-1-gubin@cmss.chinamobile.com?part=1

      reply	other threads:[~2026-11-12  8:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  8:31 [PATCH] perf trace: free intlist on filter_pids calloc failure Gu Bin
2026-11-12  8:42 ` sashiko-bot [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=sashiko-outbox-210765@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gubin@cmss.chinamobile.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