All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiebin Sun" <jiebin.sun@intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 09/14] perf c2c: add stats merging and memory management helpers
Date: Fri, 26 Jun 2026 07:17:45 +0000	[thread overview]
Message-ID: <20260626071745.E59FF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260626070355.1556721-10-jiebin.sun@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Memory leak of nested histogram entries because `hists__delete_entries()` is used instead of `hists__delete_all_entries()`.
--

commit d68acbe4d76a46f5dbb0cda5a255e3f5f919e159
Author: Jiebin Sun <jiebin.sun@intel.com>

perf c2c: add stats merging and memory management helpers

This commit adds statistics aggregation and memory management functions for
function view histogram entries, including c2c_stats_merge(),
c2c_function_he_free(), and c2c_he__free_hierarchy() to handle merging and
recursive cleanup during hierarchy construction.

> diff --git a/tools/perf/ui/browsers/c2c-function.c b/tools/perf/ui/browsers/c2c-function.c
> index c11a81d93c21e..a42378f395f59 100644
> --- a/tools/perf/ui/browsers/c2c-function.c
> +++ b/tools/perf/ui/browsers/c2c-function.c
[ ... ]
> @@ -649,6 +649,164 @@ c2c_function_hists__reinit(struct c2c_hists *c2c_hists,
[ ... ]
> +/*
> + * Free a function-view histogram entry (hist_entry_ops::free).
> + */
> +static void c2c_function_he_free(void *ptr)
> +{
> +	struct hist_entry *he = ptr;
> +	struct c2c_hist_entry *c2c_he;
> +
> +	c2c_he = container_of(he, struct c2c_hist_entry, he);
> +
> +	if (c2c_he->hists) {
> +		perf_hpp__reset_output_field(&c2c_he->hists->list);
> +		hists__delete_entries(&c2c_he->hists->hists);

[Severity: Medium]
Does this code leak nested histogram entries that haven't reached the output
sorted stage?

hists__delete_entries() only iterates over and frees entries in the output
tree. Any entries left in the input or collapsed trees might not be freed.

Should this be hists__delete_all_entries() to prevent leaking these
unprocessed entries, similar to the cleanup handling in builtin-c2c.c?

> +		zfree(&c2c_he->hists);
> +	}
> +
> +	c2c_he__free_hierarchy(he);
> +
[ ... ]
> +static void c2c_he__free_hierarchy(struct hist_entry *he)
> +{
> +	struct rb_node *nd;
> +	struct hist_entry *child_he;
> +	struct c2c_hist_entry *child_c2c;
> +
[ ... ]
> +	nd = rb_first_cached(&he->hroot_out);
> +	while (nd) {
> +		struct rb_node *next = rb_next(nd);
> +
> +		child_he = rb_entry(nd, struct hist_entry, rb_node);
> +		child_c2c = container_of(child_he, struct c2c_hist_entry, he);
> +
> +		if (child_he->stat_acc)
> +			zfree(&child_he->stat_acc);
> +
> +		if (child_he->mem_info)
> +			mem_info__put(child_he->mem_info);
> +
> +		if (child_c2c->hists) {
> +			perf_hpp__reset_output_field(&child_c2c->hists->list);
> +			hists__delete_entries(&child_c2c->hists->hists);

[Severity: Medium]
Could this recursive hierarchy deletion also leak histogram entries?

Like the issue above in c2c_function_he_free(), using hists__delete_entries()
instead of hists__delete_all_entries() skips freeing any entries that are
still in the input or collapsed trees.

> +			zfree(&child_c2c->hists);
> +		}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260626070355.1556721-1-jiebin.sun@intel.com?part=9

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

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26  7:03 [PATCH 00/14] perf c2c: add a function view Jiebin Sun
2026-06-26  7:03 ` [PATCH 01/14] perf c2c: extract shared data structures into c2c.h Jiebin Sun
2026-06-26  7:13   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 02/14] perf c2c: add function view browser skeleton Jiebin Sun
2026-06-26  7:11   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 03/14] perf c2c: add function view type definitions and helpers Jiebin Sun
2026-06-26  7:14   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 04/14] perf c2c: add column format infrastructure for function view Jiebin Sun
2026-06-26  7:03 ` [PATCH 05/14] perf c2c: add column entry functions " Jiebin Sun
2026-06-26  7:03 ` [PATCH 06/14] perf c2c: add comparison functions for function view sorting Jiebin Sun
2026-06-26  7:22   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 07/14] perf c2c: add dimension definitions and format creation Jiebin Sun
2026-06-26  7:23   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 08/14] perf c2c: add HPP list parsing for function view histograms Jiebin Sun
2026-06-26  7:16   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 09/14] perf c2c: add stats merging and memory management helpers Jiebin Sun
2026-06-26  7:17   ` sashiko-bot [this message]
2026-06-26  7:03 ` [PATCH 10/14] perf c2c: add hierarchy entry creation and lookup functions Jiebin Sun
2026-06-26  7:19   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 11/14] perf c2c: add function view hierarchy builder Jiebin Sun
2026-06-26  7:03 ` [PATCH 12/14] perf c2c: add function view browser UI Jiebin Sun
2026-06-26  7:03 ` [PATCH 13/14] perf c2c: add TAB key to switch to function view Jiebin Sun
2026-06-26  7:03 ` [PATCH 14/14] perf c2c: document function view in perf-c2c man page Jiebin Sun

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=20260626071745.E59FF1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jiebin.sun@intel.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 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.