confile: cleanup set_config_idmaps()

parent 83332c24
...@@ -2042,29 +2042,27 @@ static int set_config_proc(const char *key, const char *value, ...@@ -2042,29 +2042,27 @@ static int set_config_proc(const char *key, const char *value,
static int set_config_idmaps(const char *key, const char *value, static int set_config_idmaps(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 *idmaplist = NULL;
__do_free struct id_map *idmap = NULL;
unsigned long hostid, nsid, range; unsigned long hostid, nsid, range;
char type; char type;
int ret; int ret;
struct lxc_list *idmaplist = NULL;
struct id_map *idmap = NULL;
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_idmaps(lxc_conf); return lxc_clear_idmaps(lxc_conf);
idmaplist = malloc(sizeof(*idmaplist)); idmaplist = malloc(sizeof(*idmaplist));
if (!idmaplist) if (!idmaplist)
goto on_error; return ret_errno(ENOMEM);
idmap = malloc(sizeof(*idmap)); idmap = malloc(sizeof(*idmap));
if (!idmap) if (!idmap)
goto on_error; return ret_errno(ENOMEM);
memset(idmap, 0, sizeof(*idmap)); memset(idmap, 0, sizeof(*idmap));
ret = parse_idmaps(value, &type, &nsid, &hostid, &range); ret = parse_idmaps(value, &type, &nsid, &hostid, &range);
if (ret < 0) { if (ret < 0)
ERROR("Failed to parse id mappings"); return log_error_errno(-EINVAL, EINVAL, "Failed to parse id mappings");
goto on_error;
}
INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range); INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range);
if (type == 'u') if (type == 'u')
...@@ -2072,7 +2070,7 @@ static int set_config_idmaps(const char *key, const char *value, ...@@ -2072,7 +2070,7 @@ static int set_config_idmaps(const char *key, const char *value,
else if (type == 'g') else if (type == 'g')
idmap->idtype = ID_TYPE_GID; idmap->idtype = ID_TYPE_GID;
else else
goto on_error; return ret_errno(EINVAL);
idmap->hostid = hostid; idmap->hostid = hostid;
idmap->nsid = nsid; idmap->nsid = nsid;
...@@ -2088,15 +2086,10 @@ static int set_config_idmaps(const char *key, const char *value, ...@@ -2088,15 +2086,10 @@ static int set_config_idmaps(const char *key, const char *value,
if (idmap->nsid == 0) if (idmap->nsid == 0)
lxc_conf->root_nsgid_map = idmap; lxc_conf->root_nsgid_map = idmap;
idmap = NULL; move_ptr(idmap);
move_ptr(idmaplist);
return 0; return 0;
on_error:
free(idmaplist);
free(idmap);
return -1;
} }
static int set_config_mount_fstab(const char *key, const char *value, static int set_config_mount_fstab(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