Skip to content

Commit

Permalink
realtime/librttest: get_numcpus() fix leak
Browse files Browse the repository at this point in the history
As pointed out on the mailing list this function has
a memory leak, fixing it.

Link: https://lore.kernel.org/ltp/[email protected]/
Fixes: 591c56b ("realtime/prio-preempt: take cpu isolation into consideration")
Reviewed-by: Petr Vorel <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Attila Fazekas <[email protected]>
  • Loading branch information
afazekas authored and pevik committed Jan 23, 2025
1 parent 23277aa commit 1edca67
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions testcases/realtime/lib/librttest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 1edca67

Please sign in to comment.