confile: cleanup set_config_proc()

parent bfada1b3
...@@ -141,6 +141,16 @@ struct lxc_proc { ...@@ -141,6 +141,16 @@ struct lxc_proc {
char *value; char *value;
}; };
static void free_lxc_proc(struct lxc_proc *ptr)
{
if (ptr) {
free(ptr->filename);
free(ptr->value);
free_disarm(ptr);
}
}
define_cleanup_function(struct lxc_proc *, free_lxc_proc);
/* /*
* id_map is an id map entry. Form in confile is: * id_map is an id map entry. Form in confile is:
* lxc.idmap = u 0 9800 100 * lxc.idmap = u 0 9800 100
......
...@@ -1874,9 +1874,9 @@ static int set_config_sysctl(const char *key, const char *value, ...@@ -1874,9 +1874,9 @@ static int set_config_sysctl(const char *key, const char *value,
static int set_config_proc(const char *key, const char *value, static int set_config_proc(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
__do_free struct lxc_list *proclist = NULL;
call_cleaner(free_lxc_proc) struct lxc_proc *procelem = NULL;
const char *subkey; const char *subkey;
struct lxc_list *proclist = NULL;
struct lxc_proc *procelem = NULL;
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_proc(key, lxc_conf, NULL); return clr_config_proc(key, lxc_conf, NULL);
...@@ -1886,39 +1886,29 @@ static int set_config_proc(const char *key, const char *value, ...@@ -1886,39 +1886,29 @@ static int set_config_proc(const char *key, const char *value,
subkey = key + STRLITERALLEN("lxc.proc."); subkey = key + STRLITERALLEN("lxc.proc.");
if (*subkey == '\0') if (*subkey == '\0')
return -EINVAL; return ret_errno(EINVAL);
proclist = malloc(sizeof(*proclist)); proclist = malloc(sizeof(*proclist));
if (!proclist) if (!proclist)
goto on_error; return ret_errno(ENOMEM);
procelem = malloc(sizeof(*procelem)); procelem = malloc(sizeof(*procelem));
if (!procelem) if (!procelem)
goto on_error; return ret_errno(ENOMEM);
memset(procelem, 0, sizeof(*procelem)); memset(procelem, 0, sizeof(*procelem));
procelem->filename = strdup(subkey); procelem->filename = strdup(subkey);
procelem->value = strdup(value); if (!procelem->filename)
return ret_errno(ENOMEM);
if (!procelem->filename || !procelem->value)
goto on_error;
proclist->elem = procelem; procelem->value = strdup(value);
if (!procelem->value)
return ret_errno(ENOMEM);
lxc_list_add_tail(&lxc_conf->procs, proclist); proclist->elem = move_ptr(procelem);
lxc_list_add_tail(&lxc_conf->procs, move_ptr(proclist));
return 0; return 0;
on_error:
free(proclist);
if (procelem) {
free(procelem->filename);
free(procelem->value);
free(procelem);
}
return -1;
} }
static int set_config_idmaps(const char *key, const char *value, static int set_config_idmaps(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