[LTP] [PATCH] realtime/librttest: get_numcpus() fix leak

Petr Vorel pvorel@suse.cz
Thu Jan 23 13:08:22 CET 2025


Hi Attila,

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

Good catch, thanks!

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Actually old problem, IMHO:

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

I'll wait little longer and merge.

Kind regards,
Petr

> 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;
>  }


More information about the ltp mailing list