Skip to content

Commit 2c57d6c

Browse files
walacgregkh
authored andcommitted
rtla/utils: Fix resource leak in set_comm_sched_attr()
[ Upstream commit 5b6dc65 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6a815bb commit 2c57d6c

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
@@ -347,22 +347,23 @@ int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr)
347347

348348
if (strtoi(proc_entry->d_name, &pid)) {
349349
err_msg("'%s' is not a valid pid", proc_entry->d_name);
350-
goto out_err;
350+
retval = 1;
351+
goto out;
351352
}
352353
/* procfs_is_workload_pid confirmed it is a pid */
353354
retval = __set_sched_attr(pid, attr);
354355
if (retval) {
355356
err_msg("Error setting sched attributes for pid:%s\n", proc_entry->d_name);
356-
goto out_err;
357+
goto out;
357358
}
358359

359360
debug_msg("Set sched attributes for pid:%s\n", proc_entry->d_name);
360361
}
361-
return 0;
362362

363-
out_err:
363+
retval = 0;
364+
out:
364365
closedir(procfs);
365-
return 1;
366+
return retval;
366367
}
367368

368369
#define INVALID_VAL (~0L)

0 commit comments

Comments
 (0)