[LTP] [PATCH] realtime/librttest: get_numcpus() fix leak
Attila Fazekas
afazekas@redhat.com
Thu Jan 23 12:18:54 CET 2025
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
More information about the ltp
mailing list