Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH, next, v2] perf iostat: Release the port list if command allocation fails
@ 2026-11-09  9:01 lirongqing
  2026-11-09  9:06 ` sashiko-bot
  2026-11-11 19:09 ` Namhyung Kim
  0 siblings, 2 replies; 3+ messages in thread
From: lirongqing @ 2026-11-09  9:01 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark, Li RongQing,
	Alexander Antonov, linux-perf-users, linux-kernel

From: Li RongQing <lirongqing@baidu.com>

iostat_event_group() takes ownership of the root port list and frees it
via the err: label on both the normal and parsing-error paths. When
calloc() for iostat_cmd fails, however, the function returns -ENOMEM
directly, leaking the list, its pointer array and every port in it.

Route this failure through the existing cleanup path instead. At this
point no port has been transferred to an event yet, so
iio_root_ports_list_free() releases the whole list, and the trailing
free(iostat_cmd) is a no-op on the NULL pointer.

Fixes: f9ed693e8bc0 ("perf stat: Enable iostat mode for x86 platforms")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
Diff with v1: rebase to next

 tools/perf/arch/x86/util/iostat.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c
index 7442a2c..d2cc2e7 100644
--- a/tools/perf/arch/x86/util/iostat.c
+++ b/tools/perf/arch/x86/util/iostat.c
@@ -310,8 +310,10 @@ static int iostat_event_group(struct evlist *evl,
 	int metrics_count = iostat_metrics_count();
 	char *iostat_cmd = calloc(len_template, 1);
 
-	if (!iostat_cmd)
-		return -ENOMEM;
+	if (!iostat_cmd) {
+		ret = -ENOMEM;
+		goto err;
+	}
 
 	for (idx = 0; idx < list->nr_entries; idx++) {
 		sprintf(iostat_cmd, iostat_cmd_template,
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-11 19:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09  9:01 [PATCH, next, v2] perf iostat: Release the port list if command allocation fails lirongqing
2026-11-09  9:06 ` sashiko-bot
2026-11-11 19:09 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox