]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: cleanup set_config_group()
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Dec 2020 13:43:50 +0000 (14:43 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Dec 2020 14:40:48 +0000 (15:40 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c

index 4d1acc1fb14cc0742b80d96af0a9989801715cc9..6900111dd071b6c79da2a1dd9f89401fd4b21e51 100644 (file)
@@ -1358,40 +1358,34 @@ static int set_config_monitor_signal_pdeath(const char *key, const char *value,
 static int set_config_group(const char *key, const char *value,
                            struct lxc_conf *lxc_conf, void *data)
 {
-       char *groups, *token;
-       struct lxc_list *grouplist;
-       int ret = 0;
+       __do_free char *groups = NULL;
+       char *token;
 
        if (lxc_config_value_empty(value))
                return lxc_clear_groups(lxc_conf);
 
        groups = strdup(value);
        if (!groups)
-               return -1;
+               return ret_errno(ENOMEM);
 
        /* In case several groups are specified in a single line split these
         * groups in a single element for the list.
         */
        lxc_iterate_parts(token, groups, " \t") {
+               __do_free struct lxc_list *grouplist = NULL;
+
                grouplist = malloc(sizeof(*grouplist));
-               if (!grouplist) {
-                       ret = -1;
-                       break;
-               }
+               if (!grouplist)
+                       return ret_errno(ENOMEM);
 
                grouplist->elem = strdup(token);
-               if (!grouplist->elem) {
-                       free(grouplist);
-                       ret = -1;
-                       break;
-               }
+               if (!grouplist->elem)
+                       return ret_errno(ENOMEM);
 
-               lxc_list_add_tail(&lxc_conf->groups, grouplist);
+               lxc_list_add_tail(&lxc_conf->groups, move_ptr(grouplist));
        }
 
-       free(groups);
-
-       return ret;
+       return 0;
 }
 
 static int set_config_environment(const char *key, const char *value,