]> git.proxmox.com Git - mirror_lxc.git/commitdiff
confile: cleanup set_config_cap_keep()
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Dec 2020 14:46:42 +0000 (15:46 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Dec 2020 15:49:39 +0000 (16:49 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c

index e1ebe04137403c8d4206f343d1521cf2cc6290c4..622a0ac6bbd6e660898b08a89594d8c2feadd5e9 100644 (file)
@@ -2235,16 +2235,16 @@ int add_elem_to_mount_list(const char *value, struct lxc_conf *lxc_conf) {
 static int set_config_cap_keep(const char *key, const char *value,
                               struct lxc_conf *lxc_conf, void *data)
 {
-       char *keepcaps, *token;
-       struct lxc_list *keeplist;
-       int ret = -1;
+       __do_free char *keepcaps = NULL;
+       __do_free struct lxc_list *keeplist = NULL;
+       char *token;
 
        if (lxc_config_value_empty(value))
                return lxc_clear_config_keepcaps(lxc_conf);
 
        keepcaps = strdup(value);
        if (!keepcaps)
-               return -1;
+               return ret_errno(ENOMEM);
 
        /* In case several capability keep is specified in a single line
         * split these caps in a single element for the list.
@@ -2255,23 +2255,16 @@ static int set_config_cap_keep(const char *key, const char *value,
 
                keeplist = malloc(sizeof(*keeplist));
                if (!keeplist)
-                       goto on_error;
+                       return ret_errno(ENOMEM);
 
                keeplist->elem = strdup(token);
-               if (!keeplist->elem) {
-                       free(keeplist);
-                       goto on_error;
-               }
+               if (!keeplist->elem)
+                       return ret_errno(ENOMEM);
 
-               lxc_list_add_tail(&lxc_conf->keepcaps, keeplist);
+               lxc_list_add_tail(&lxc_conf->keepcaps, move_ptr(keeplist));
        }
 
-       ret = 0;
-
-on_error:
-       free(keepcaps);
-
-       return ret;
+       return 0;
 }
 
 static int set_config_cap_drop(const char *key, const char *value,