Skip to content

Commit 5b6dc65

Browse files
walaclenticularis39
authored andcommitted
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: dada03d ("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>
1 parent 47dd74f commit 5b6dc65

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

tools/tracing/rtla/src/utils.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,22 +390,23 @@ int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr)
390390

391391
if (strtoi(proc_entry->d_name, &pid)) {
392392
err_msg("'%s' is not a valid pid", proc_entry->d_name);
393-
goto out_err;
393+
retval = 1;
394+
goto out;
394395
}
395396
/* procfs_is_workload_pid confirmed it is a pid */
396397
retval = __set_sched_attr(pid, attr);
397398
if (retval) {
398399
err_msg("Error setting sched attributes for pid:%s\n", proc_entry->d_name);
399-
goto out_err;
400+
goto out;
400401
}
401402

402403
debug_msg("Set sched attributes for pid:%s\n", proc_entry->d_name);
403404
}
404-
return 0;
405405

406-
out_err:
406+
retval = 0;
407+
out:
407408
closedir(procfs);
408-
return 1;
409+
return retval;
409410
}
410411

411412
#define INVALID_VAL (~0L)

0 commit comments

Comments
 (0)