confile: cleanup __set_config_cgroup_controller()

parent c4d9b159
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "list.h" #include "list.h"
#include "lxcseccomp.h" #include "lxcseccomp.h"
#include "memory_utils.h"
#include "ringbuf.h" #include "ringbuf.h"
#include "start.h" #include "start.h"
#include "terminal.h" #include "terminal.h"
...@@ -69,6 +70,16 @@ struct lxc_cgroup { ...@@ -69,6 +70,16 @@ struct lxc_cgroup {
}; };
}; };
static void free_lxc_cgroup(struct lxc_cgroup *ptr)
{
if (ptr) {
free(ptr->subsystem);
free(ptr->value);
free_disarm(ptr);
}
}
define_cleanup_function(struct lxc_cgroup *, free_lxc_cgroup);
#if !HAVE_SYS_RESOURCE_H #if !HAVE_SYS_RESOURCE_H
#define RLIM_INFINITY ((unsigned long)-1) #define RLIM_INFINITY ((unsigned long)-1)
struct rlimit { struct rlimit {
......
...@@ -1686,10 +1686,10 @@ static int set_config_signal_stop(const char *key, const char *value, ...@@ -1686,10 +1686,10 @@ static int set_config_signal_stop(const char *key, const char *value,
static int __set_config_cgroup_controller(const char *key, const char *value, static int __set_config_cgroup_controller(const char *key, const char *value,
struct lxc_conf *lxc_conf, int version) struct lxc_conf *lxc_conf, int version)
{ {
__do_free struct lxc_list *cglist = NULL;
call_cleaner(free_lxc_cgroup) struct lxc_cgroup *cgelem = NULL;
const char *subkey, *token; const char *subkey, *token;
size_t token_len; size_t token_len;
struct lxc_list *cglist = NULL;
struct lxc_cgroup *cgelem = NULL;
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_cgroups(lxc_conf, key, version); return lxc_clear_cgroups(lxc_conf, key, version);
...@@ -1701,53 +1701,44 @@ static int __set_config_cgroup_controller(const char *key, const char *value, ...@@ -1701,53 +1701,44 @@ static int __set_config_cgroup_controller(const char *key, const char *value,
token = "lxc.cgroup."; token = "lxc.cgroup.";
token_len = 11; token_len = 11;
} else { } else {
return -EINVAL; return ret_errno(EINVAL);
} }
if (strncmp(key, token, token_len) != 0) if (strncmp(key, token, token_len) != 0)
return -EINVAL; return ret_errno(EINVAL);
subkey = key + token_len; subkey = key + token_len;
if (*subkey == '\0') if (*subkey == '\0')
return -EINVAL; return ret_errno(EINVAL);
cglist = malloc(sizeof(*cglist)); cglist = malloc(sizeof(*cglist));
if (!cglist) if (!cglist)
goto out; return ret_errno(ENOMEM);
cgelem = malloc(sizeof(*cgelem)); cgelem = malloc(sizeof(*cgelem));
if (!cgelem) if (!cgelem)
goto out; return ret_errno(ENOMEM);
memset(cgelem, 0, sizeof(*cgelem)); memset(cgelem, 0, sizeof(*cgelem));
cgelem->subsystem = strdup(subkey); cgelem->subsystem = strdup(subkey);
if (!cgelem->subsystem) if (!cgelem->subsystem)
goto out; return ret_errno(ENOMEM);
cgelem->value = strdup(value); cgelem->value = strdup(value);
if (!cgelem->value) if (!cgelem->value)
goto out; return ret_errno(ENOMEM);
cgelem->version = version; cgelem->version = version;
lxc_list_add_elem(cglist, cgelem); lxc_list_add_elem(cglist, move_ptr(cgelem));
if (version == CGROUP2_SUPER_MAGIC) if (version == CGROUP2_SUPER_MAGIC)
lxc_list_add_tail(&lxc_conf->cgroup2, cglist); lxc_list_add_tail(&lxc_conf->cgroup2, cglist);
else else
lxc_list_add_tail(&lxc_conf->cgroup, cglist); lxc_list_add_tail(&lxc_conf->cgroup, cglist);
move_ptr(cglist);
return 0; return 0;
out:
free(cglist);
if (cgelem) {
free(cgelem->subsystem);
free(cgelem->value);
free(cgelem);
}
return -1;
} }
static int set_config_cgroup_controller(const char *key, const char *value, static int set_config_cgroup_controller(const char *key, const char *value,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment