]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/cgroups/cgfsng.c
cgroups: move variable into tighter scope
[mirror_lxc.git] / src / lxc / cgroups / cgfsng.c
index 62b7a87b03b3b8c53e5bcdbc3e193d03ba664e1b..f29ccd1bcc11a6c9ccc03585c75c9248da477073 100644 (file)
@@ -320,6 +320,7 @@ static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
 {
        int ret;
        size_t i;
+       char *tmp = NULL;
        char **cpulist = NULL;
        char numstr[INTTYPE_TO_STRLEN(size_t)] = {0};
 
@@ -343,7 +344,10 @@ static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
        if (!cpulist)
                return NULL;
 
-       return lxc_string_join(",", (const char **)cpulist, false);
+       tmp = lxc_string_join(",", (const char **)cpulist, false);
+       lxc_free_array((void **)cpulist, free);
+
+       return tmp;
 }
 
 static ssize_t get_max_cpus(char *cpulist)
@@ -2082,7 +2086,7 @@ on_error:
 __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops, const char *name,
                                         const char *lxcpath, pid_t pid)
 {
-       int i, len, ret;
+       int len, ret;
        char pidstr[INTTYPE_TO_STRLEN(pid_t)];
 
        if (!ops->hierarchies)
@@ -2092,9 +2096,8 @@ __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops, const char *name,
        if (len < 0 || (size_t)len >= sizeof(pidstr))
                return false;
 
-       for (i = 0; ops->hierarchies[i]; i++) {
-               __do_free char *path = NULL;
-               char *fullpath = NULL;
+       for (int i = 0; ops->hierarchies[i]; i++) {
+               __do_free char *fullpath = NULL, *path = NULL;
                struct hierarchy *h = ops->hierarchies[i];
 
                if (h->version == CGROUP2_SUPER_MAGIC) {
@@ -2392,13 +2395,10 @@ static bool __cg_unified_setup_limits(struct cgroup_ops *ops,
 }
 
 __cgfsng_ops static bool cgfsng_setup_limits(struct cgroup_ops *ops,
-                                              struct lxc_conf *conf,
-                                              bool do_devices)
+                                            struct lxc_conf *conf,
+                                            bool do_devices)
 {
-       bool bret;
-
-       bret = __cg_legacy_setup_limits(ops, &conf->cgroup, do_devices);
-       if (!bret)
+       if (!__cg_legacy_setup_limits(ops, &conf->cgroup, do_devices))
                return false;
 
        return __cg_unified_setup_limits(ops, &conf->cgroup2);
@@ -2407,15 +2407,13 @@ __cgfsng_ops static bool cgfsng_setup_limits(struct cgroup_ops *ops,
 static bool cgroup_use_wants_controllers(const struct cgroup_ops *ops,
                                       char **controllers)
 {
-       char **cur_ctrl, **cur_use;
-
        if (!ops->cgroup_use)
                return true;
 
-       for (cur_ctrl = controllers; cur_ctrl && *cur_ctrl; cur_ctrl++) {
+       for (char **cur_ctrl = controllers; cur_ctrl && *cur_ctrl; cur_ctrl++) {
                bool found = false;
 
-               for (cur_use = ops->cgroup_use; cur_use && *cur_use; cur_use++) {
+               for (char **cur_use = ops->cgroup_use; cur_use && *cur_use; cur_use++) {
                        if (strcmp(*cur_use, *cur_ctrl) != 0)
                                continue;
 
@@ -2750,7 +2748,7 @@ __cgfsng_ops static bool cgfsng_data_init(struct cgroup_ops *ops)
 
 struct cgroup_ops *cgfsng_ops_init(struct lxc_conf *conf)
 {
-       struct cgroup_ops *cgfsng_ops;
+       __do_free struct cgroup_ops *cgfsng_ops = NULL;
 
        cgfsng_ops = malloc(sizeof(struct cgroup_ops));
        if (!cgfsng_ops)
@@ -2759,10 +2757,8 @@ struct cgroup_ops *cgfsng_ops_init(struct lxc_conf *conf)
        memset(cgfsng_ops, 0, sizeof(struct cgroup_ops));
        cgfsng_ops->cgroup_layout = CGROUP_LAYOUT_UNKNOWN;
 
-       if (!cg_init(cgfsng_ops, conf)) {
-               free(cgfsng_ops);
+       if (!cg_init(cgfsng_ops, conf))
                return NULL;
-       }
 
        cgfsng_ops->data_init = cgfsng_data_init;
        cgfsng_ops->payload_destroy = cgfsng_payload_destroy;
@@ -2786,5 +2782,5 @@ struct cgroup_ops *cgfsng_ops_init(struct lxc_conf *conf)
        cgfsng_ops->mount = cgfsng_mount;
        cgfsng_ops->nrtasks = cgfsng_nrtasks;
 
-       return cgfsng_ops;
+       return move_ptr(cgfsng_ops);
 }