From: Christian Brauner Date: Tue, 16 Feb 2021 17:38:26 +0000 (+0100) Subject: cgroups: fix fd leaks X-Git-Tag: lxc-5.0.0~285^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c426abeaa940bfbdb6df0560d7924050cd9c7ae8;p=thirdparty%2Flxc.git cgroups: fix fd leaks They didn't really matter because we want to keep them around for as long as the container lives anyway. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cgroups/cgroup.c b/src/lxc/cgroups/cgroup.c index b83879b62..96049b359 100644 --- a/src/lxc/cgroups/cgroup.c +++ b/src/lxc/cgroups/cgroup.c @@ -86,16 +86,34 @@ void cgroup_exit(struct cgroup_ops *ops) free((*it)->mountpoint); free((*it)->container_base_path); - free((*it)->container_full_path); - free((*it)->monitor_full_path); - if ((*it)->cgfd_con >= 0) - close((*it)->cgfd_con); + + { + free((*it)->container_full_path); + + if ((*it)->container_full_path != (*it)->container_limit_path) + free((*it)->monitor_full_path); + } + + { + if ((*it)->cgfd_limit >= 0 && (*it)->cgfd_con != (*it)->cgfd_limit) + close((*it)->cgfd_limit); + + if ((*it)->cgfd_con >= 0) + close((*it)->cgfd_con); + + } + if ((*it)->cgfd_mon >= 0) close((*it)->cgfd_mon); - if ((*it)->dfd_mnt >= 0) - close((*it)->dfd_mnt); - if ((*it)->dfd_base >= 0) - close((*it)->dfd_base); + + { + if ((*it)->dfd_base >= 0 && (*it)->dfd_mnt != (*it)->dfd_base) + close((*it)->dfd_base); + + if ((*it)->dfd_mnt >= 0) + close((*it)->dfd_mnt); + } + free(*it); } free(ops->hierarchies);