]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: use close_equal() and free_equal()
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 18 Feb 2021 14:52:52 +0000 (15:52 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 18 Feb 2021 14:55:24 +0000 (15:55 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c
src/lxc/cgroups/cgroup.c

index c8441e7e63194cba4b5dad8dc3a3b19f6eeb24bc..16cee9f0d11547d59906328df105d8407f61bd4a 100644 (file)
@@ -797,9 +797,7 @@ static int cgroup_tree_remove(struct hierarchy **hierarchies, const char *path_p
                else
                        TRACE("Removed cgroup tree %d(%s)", h->dfd_base, path_prune);
 
-               if (h->container_limit_path != h->container_full_path)
-                       free_disarm(h->container_limit_path);
-               free_disarm(h->container_full_path);
+               free_equal(h->container_limit_path, h->container_full_path);
        }
 
        return 0;
@@ -1185,12 +1183,8 @@ static void cgroup_tree_prune_leaf(struct hierarchy *h, const char *path_prune,
                if (h->cgfd_limit < 0)
                        prune = false;
 
-               if (h->container_full_path != h->container_limit_path)
-                       free_disarm(h->container_limit_path);
-               free_disarm(h->container_full_path);
-
-               close_prot_errno_disarm(h->cgfd_con);
-               close_prot_errno_disarm(h->cgfd_limit);
+               free_equal(h->container_full_path, h->container_limit_path);
+               close_equal(h->cgfd_con, h->cgfd_limit);
        } else {
                /* Check whether we actually created the cgroup to prune. */
                if (h->cgfd_mon < 0)
index ddd16a3be3ddc5d61067cf23c74e9a0eee787dfa..775f79f62d0d5cf1c4cad9b1d0431cd36e070464 100644 (file)
@@ -14,6 +14,7 @@
 #include "conf.h"
 #include "config.h"
 #include "initutils.h"
+#include "memory_utils.h"
 #include "log.h"
 #include "start.h"
 #include "string_utils.h"
@@ -68,11 +69,7 @@ void cgroup_exit(struct cgroup_ops *ops)
        free(ops->cgroup_pattern);
        free(ops->monitor_cgroup);
 
-       {
-               if (ops->container_cgroup != ops->container_limit_cgroup)
-                       free(ops->container_limit_cgroup);
-               free(ops->container_cgroup);
-       }
+       free_equal(ops->container_cgroup, ops->container_limit_cgroup);
 
        if (ops->cgroup2_devices)
                bpf_program_free(ops->cgroup2_devices);
@@ -92,32 +89,15 @@ void cgroup_exit(struct cgroup_ops *ops)
                free((*it)->mountpoint);
                free((*it)->container_base_path);
 
-               {
-                       free((*it)->container_full_path);
-
-                       if ((*it)->container_full_path != (*it)->container_limit_path)
-                               free((*it)->container_limit_path);
-               }
-
-               {
-                       if ((*it)->cgfd_limit >= 0 && (*it)->cgfd_con != (*it)->cgfd_limit)
-                               close((*it)->cgfd_limit);
+               free_equal((*it)->container_full_path,
+                          (*it)->container_limit_path);
 
-                       if ((*it)->cgfd_con >= 0)
-                               close((*it)->cgfd_con);
-
-               }
+               close_equal((*it)->cgfd_con, (*it)->cgfd_limit);
 
                if ((*it)->cgfd_mon >= 0)
                        close((*it)->cgfd_mon);
 
-               {
-                       if ((*it)->dfd_base >= 0 && (*it)->dfd_mnt != (*it)->dfd_base)
-                               close((*it)->dfd_base);
-
-                       if ((*it)->dfd_mnt >= 0)
-                               close((*it)->dfd_mnt);
-               }
+               close_equal((*it)->dfd_base, (*it)->dfd_mnt);
 
                free(*it);
        }