Thread (16 messages) flat view 16 messages, 4 authors, 6d ago

Re: [PATCH v7 3/6] perf header: Support memory ranges

From: sashiko-bot@kernel.org
Date: 2026-09-09 16:15:36

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Potential memory leak of `env->memory_ranges` in `process_memory_ranges` when called multiple times.
--

commit 9619ae1d9d691918f8e1f649f853a92424ed440c
Author: Thomas Falcon [off-list ref]

perf header: Support memory ranges

This commit introduces support for tracking and exposing memory ranges parsed
from the ACPI MRRM table. It reads memory range data from sysfs and saves it
in the perf data file under the new HEADER_MEMORY_RANGES feature bit.

Link: https://lore.kernel.org/lkml/20250505173819.419271-1-tony.luck@intel.com/ (local)
quoted hunk ↗ jump to hunk
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 7db7da090a1e0..83416ce395d7c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -4202,6 +4346,64 @@ static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_unused
 	return ret;
 }
 
+static int process_memory_ranges(struct feat_fd *ff, void *data __maybe_unused)
+{
+	struct perf_env *env = &ff->ph->env;
+	struct memory_range *ranges, *r;
+	u32 nr_memory_ranges, i;
[ ... ]
+	ranges = calloc(nr_memory_ranges, sizeof(*ranges));
+	if (!ranges)
+		return -1;
+
+	for (i = 0; i < nr_memory_ranges; i++) {
+		r = &ranges[i];
+
+		if (do_read_u64(ff, &r->base))
+			goto error;
+		if (do_read_u64(ff, &r->length))
+			goto error;
+		if (do_read_u32(ff, (u32 *) &r->node))
+			goto error;
+		if (__do_read(ff, &r->local_region_id, sizeof(u8)))
+			goto error;
+		if (__do_read(ff, &r->remote_region_id, sizeof(u8)))
+			goto error;
+	}
+
+	env->memory_ranges = ranges;
+	env->nr_memory_ranges = nr_memory_ranges;
[Severity: Medium]
Could this result in a memory leak of the previous env->memory_ranges
allocation?

In pipe mode, the perf_event__process_feature() function parses feature
headers as they arrive and dispatches them to process_memory_ranges(). If
the HEADER_MEMORY_RANGES feature is encountered multiple times in a data
stream, this assigns the newly allocated array to env->memory_ranges without
freeing the previous array.
+
+	return 0;
+error:
+	zfree(&ranges);
+	return -1;
+}
-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909160218.174928-1-thomas.falcon@intel.com?part=3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help