]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroup_utils: use __do_free
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 9 Feb 2019 10:51:04 +0000 (11:51 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 17 Feb 2019 13:13:44 +0000 (14:13 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgroup_utils.c

index 5a44f36db906d637e7757e14df1f2415dc2a43f5..1b780b2bc2a64fa380e91693da318039185c91fc 100644 (file)
@@ -33,6 +33,7 @@
 #include "cgroup_utils.h"
 #include "config.h"
 #include "macro.h"
+#include "memory_utils.h"
 #include "utils.h"
 
 int get_cgroup_version(char *line)
@@ -65,12 +66,8 @@ bool is_cgroupfs_v2(char *line)
 
 bool test_writeable_v1(char *mountpoint, char *path)
 {
-       char *fullpath = must_make_path(mountpoint, path, NULL);
-       int ret;
-
-       ret = access(fullpath, W_OK);
-       free(fullpath);
-       return ret == 0;
+       __do_free char *fullpath = must_make_path(mountpoint, path, NULL);
+       return (access(fullpath, W_OK) == 0);
 }
 
 bool test_writeable_v2(char *mountpoint, char *path)
@@ -81,39 +78,26 @@ bool test_writeable_v2(char *mountpoint, char *path)
         * file.
         */
        int ret;
-       char *cgroup_path, *cgroup_procs_file, *cgroup_threads_file;
+       __do_free char *cgroup_path = NULL, *cgroup_procs_file = NULL,
+                      *cgroup_threads_file = NULL;
 
        cgroup_path = must_make_path(mountpoint, path, NULL);
        cgroup_procs_file = must_make_path(cgroup_path, "cgroup.procs", NULL);
 
        ret = access(cgroup_path, W_OK);
-       if (ret < 0) {
-               free(cgroup_path);
-               free(cgroup_procs_file);
+       if (ret < 0)
                return false;
-       }
 
        ret = access(cgroup_procs_file, W_OK);
-       free(cgroup_procs_file);
-       if (ret < 0) {
-               free(cgroup_path);
+       if (ret < 0)
                return false;
-       }
 
        /* Newer versions of cgroup2 now also require write access to the
         * "cgroup.threads" file.
         */
        cgroup_threads_file = must_make_path(cgroup_path, "cgroup.threads", NULL);
-       free(cgroup_path);
-       if (!file_exists(cgroup_threads_file)) {
-               free(cgroup_threads_file);
+       if (!file_exists(cgroup_threads_file))
                return true;
-       }
-
-       ret = access(cgroup_threads_file, W_OK);
-       free(cgroup_threads_file);
-       if (ret < 0)
-               return false;
 
-       return ret == 0;
+       return (access(cgroup_threads_file, W_OK) == 0);
 }