]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgexec: fix memory leak in find_scope_pid()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Sun, 18 Jun 2023 07:10:33 +0000 (12:40 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 21 Jun 2023 16:14:42 +0000 (10:14 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgexec.c

index 11246273fccff5239240963f322808db6e38e9af..c0a2feffa16ac9b3cc87c1f91c9d181856dea4d0 100644 (file)
@@ -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;