public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] realtime/librttest: get_numcpus() fix leak
@ 2025-01-23 11:18 Attila Fazekas
  2025-01-23 12:08 ` Petr Vorel
  2025-01-23 14:22 ` Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Attila Fazekas @ 2025-01-23 11:18 UTC (permalink / raw)
  To: ltp; +Cc: Attila Fazekas

As pointed out on the mailing list this function has
a memory leak, fixing it.

Signed-off-by: Attila Fazekas <afazekas@redhat.com>
---
 testcases/realtime/lib/librttest.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/testcases/realtime/lib/librttest.c b/testcases/realtime/lib/librttest.c
index 03566f36d..99ce78b33 100644
--- a/testcases/realtime/lib/librttest.c
+++ b/testcases/realtime/lib/librttest.c
@@ -768,11 +768,13 @@ int get_numcpus(void)
 {
 	long numcpus_conf = sysconf(_SC_NPROCESSORS_CONF);
 	size_t size = CPU_ALLOC_SIZE(numcpus_conf);
+	int cpu_count;
 	cpu_set_t *cpuset = CPU_ALLOC(numcpus_conf);
 
 	CPU_ZERO_S(size, cpuset);
 	/* Get the number of cpus accessible to the current process */
 	sched_getaffinity(0, size, cpuset);
-
-	return CPU_COUNT_S(size, cpuset);
+	cpu_count = CPU_COUNT_S(size, cpuset);
+	CPU_FREE(cpuset);
+	return cpu_count;
 }
-- 
2.47.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2025-01-23 18:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-23 11:18 [LTP] [PATCH] realtime/librttest: get_numcpus() fix leak Attila Fazekas
2025-01-23 12:08 ` Petr Vorel
2025-01-23 14:22 ` Cyril Hrubis
2025-01-23 18:18   ` Petr Vorel

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