Skip to content

Commit

Permalink
Merge pull request #3382 from brauner/2020-04-15/fixes
Browse files Browse the repository at this point in the history
conf: correctly cleanup memory in get_minimal_idmap()
  • Loading branch information
stgraber committed Apr 15, 2020
2 parents 55785a2 + 47649d5 commit 2c6e898
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/lxc/conf.c
Expand Up @@ -3985,45 +3985,35 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf,
tmplist = malloc(sizeof(*tmplist));
if (!tmplist)
return NULL;
lxc_list_add_elem(tmplist, container_root_uid);
/* idmap will now keep track of that memory. */
lxc_list_add_elem(tmplist, move_ptr(host_uid_map));
lxc_list_add_tail(idmap, tmplist);

if (container_root_uid) {
/* idmap will now keep track of that memory. */
move_ptr(container_root_uid);

/* Add container root to the map. */
tmplist = malloc(sizeof(*tmplist));
if (!tmplist)
return NULL;
lxc_list_add_elem(tmplist, host_uid_map);
/* idmap will now keep track of that memory. */
lxc_list_add_elem(tmplist, move_ptr(container_root_uid));
lxc_list_add_tail(idmap, tmplist);
}
/* idmap will now keep track of that memory. */
move_ptr(container_root_uid);
/* idmap will now keep track of that memory. */
move_ptr(host_uid_map);

tmplist = malloc(sizeof(*tmplist));
if (!tmplist)
return NULL;
lxc_list_add_elem(tmplist, container_root_gid);
/* idmap will now keep track of that memory. */
lxc_list_add_elem(tmplist, move_ptr(host_gid_map));
lxc_list_add_tail(idmap, tmplist);

if (container_root_gid) {
/* idmap will now keep track of that memory. */
move_ptr(container_root_gid);

tmplist = malloc(sizeof(*tmplist));
if (!tmplist)
return NULL;
lxc_list_add_elem(tmplist, host_gid_map);
/* idmap will now keep track of that memory. */
lxc_list_add_elem(tmplist, move_ptr(container_root_gid));
lxc_list_add_tail(idmap, tmplist);
}
/* idmap will now keep track of that memory. */
move_ptr(container_root_gid);
/* idmap will now keep track of that memory. */
move_ptr(host_gid_map);

TRACE("Allocated minimal idmapping for ns uid %d and ns gid %d", nsuid, nsgid);

Expand Down

0 comments on commit 2c6e898

Please sign in to comment.