From: Kamalesh Babulal Date: Sun, 18 Jun 2023 07:10:33 +0000 (+0530) Subject: tools/cgexec: fix memory leak in find_scope_pid() X-Git-Tag: v3.1.0~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a48fdc10bfec553fa63fdc6018ebf9c9c464e1d;p=thirdparty%2Flibcgroup.git tools/cgexec: fix memory leak in find_scope_pid() Fix a memory leak, reported by the Coverity tool. CID 321265 (#1-2 of 2): Resource leak (RESOURCE_LEAK)37. leaked_storage: Variable pids going out of scope leaks the storage it points to. find_scope_pid (), calls cgroup_get_procs() to get the pids of the tasks under cgroup name, and it's up to the caller to free the allocated pids. Fix it by calling free(pids) after every call to cgroup_get_procs(). Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/tools/cgexec.c b/src/tools/cgexec.c index 11246273..c0a2feff 100644 --- a/src/tools/cgexec.c +++ b/src/tools/cgexec.c @@ -335,6 +335,8 @@ static pid_t find_scope_pid(pid_t pid) * have libcgroup_systemd_idle_thread */ _scope_pid = search_systemd_idle_thread_task(pids, size); + free(pids); + if (_scope_pid == -1) continue;