Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rtla/utils: Fix resource leak in set_comm_sched_attr()

The set_comm_sched_attr() function opens the /proc directory via
opendir() but fails to call closedir() on its successful exit path.
If the function iterates through all processes without error, it
returns 0 directly, leaking the DIR stream pointer.

Fix this by refactoring the function to use a single exit path. A
retval variable is introduced to track the success or failure status.
All exit points now jump to a unified out label that calls closedir()
before the function returns, ensuring the resource is always freed.

Fixes: dada03db9bb19 ("rtla: Remove procps-ng dependency")
Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Link: https://lore.kernel.org/r/20260309195040.1019085-18-wander@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>

authored by

Wander Lairson Costa and committed by
Tomas Glozar
5b6dc659 47dd74f6

+6 -5
+6 -5
tools/tracing/rtla/src/utils.c
··· 390 390 391 391 if (strtoi(proc_entry->d_name, &pid)) { 392 392 err_msg("'%s' is not a valid pid", proc_entry->d_name); 393 - goto out_err; 393 + retval = 1; 394 + goto out; 394 395 } 395 396 /* procfs_is_workload_pid confirmed it is a pid */ 396 397 retval = __set_sched_attr(pid, attr); 397 398 if (retval) { 398 399 err_msg("Error setting sched attributes for pid:%s\n", proc_entry->d_name); 399 - goto out_err; 400 + goto out; 400 401 } 401 402 402 403 debug_msg("Set sched attributes for pid:%s\n", proc_entry->d_name); 403 404 } 404 - return 0; 405 405 406 - out_err: 406 + retval = 0; 407 + out: 407 408 closedir(procfs); 408 - return 1; 409 + return retval; 409 410 } 410 411 411 412 #define INVALID_VAL (~0L)