Skip to contentSkip to conversation

realtime/librttest: get_numcpus() fix leak

PATCH In review Attila Fazekas 3 participants 4 messages Jan 23, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 realtime/librttest: get_numcpus() fix leak

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

---
 testcases/realtime/lib/librttest.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
testcases/realtime/lib/librttest.c +4 -2
index 03566f36d..99ce78b33 100644
@@ -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;
 }
Signature · 5 lines
2.47.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw

Hi Attila,

Quoted 2 lines

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

Good catch, thanks!

Actually old problem, IMHO:

Fixes 591c56b045 ("realtime/prio-preempt: take cpu isolation into consideration")

I'll wait little longer and merge.

Kind regards,
Petr

Quoted 25 lines
---
 testcases/realtime/lib/librttest.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
testcases/realtime/lib/librttest.c +4 -2
index 03566f36d..99ce78b33 100644
@@ -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;
 }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Attila, all,

thanks, fix merged!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp