]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: fix fd leaks
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 16 Feb 2021 17:38:26 +0000 (18:38 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 16 Feb 2021 18:19:09 +0000 (19:19 +0100)
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 <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgroup.c

index b83879b62b93362451627b970a2a050639361af8..96049b359e80e1c0ef62f82ae15135ca9fcedfee 100644 (file)
@@ -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);