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 parse-events: free evsel and config terms if term conversion fails
Date: Fri, 13 Nov 2026 09:00:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-212492@kernel.org> (raw)
In-Reply-To: <20261113085202.2334-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 parse-events: memory leak in parse_events_terms__copy()
  [1]
--

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

perf parse-events: free evsel and config terms if term conversion fails

This commit frees the partially populated config_terms list and releases the
allocated evsel when get_config_terms() fails in add_tracepoint().

> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index f3ba70d4f76b2..e4f8425321451 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -490,8 +490,11 @@ static int add_tracepoint(struct parse_events_state *parse_state,
>  	if (head_config) {
>  		LIST_HEAD(config_terms);
>  
> -		if (get_config_terms(head_config, &config_terms))
> +		if (get_config_terms(head_config, &config_terms)) {
> +			free_config_terms(&config_terms);
> +			evsel__put(evsel);
>  			return -ENOMEM;
> +		}
>  		list_splice(&config_terms, &evsel->config_terms);
>  	}

[Severity: Medium]
This problem wasn't introduced by this patch, but can
parse_events_terms__copy() similarly leak [1] the cloned terms on
dest->terms when parse_events_term__clone() fails partway through the list?

tools/perf/util/parse-events.c:parse_events_terms__copy() {
	list_for_each_entry (term, &src->terms, list) {
		struct parse_events_term *n;
		int ret;

		ret = parse_events_term__clone(&n, term);
		if (ret)
			return ret;

		list_add_tail(&n->list, &dest->terms);
	}
	return 0;
}

When parse_events_add_pmu() or parse_events_multi_pmu_add() calls
parse_events_terms__copy() into a local parsed_terms struct and returns on
error without calling parse_events_terms__exit(), any already cloned
parse_events_term entries and their strings are leaked.

[1] https://sashiko.dev/#/bug/linux-dd6119ed-0ace-40b2-bfe9-492b265c7283

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

      reply	other threads:[~2026-11-13  9:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  8:52 [PATCH] perf parse-events: free evsel and config terms if term conversion fails Gu Bin
2026-11-13  9:00 ` 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-212492@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