Skip to content

Commit

Permalink
Check malloc failure when sorting cgroup settings.
Browse files Browse the repository at this point in the history
Signed-off-by: Kien Truong <duckientruong@gmail.com>
  • Loading branch information
kien-truong committed May 4, 2015
1 parent aaf2683 commit fac7c66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lxc/cgfs.c
Expand Up @@ -1895,6 +1895,9 @@ static int do_setup_cgroup_limits(struct cgfs_data *d,
return 0;

sorted_cgroup_settings = sort_cgroup_settings(cgroup_settings);
if (!sorted_cgroup_settings) {
return -1;
}

lxc_list_for_each(iterator, sorted_cgroup_settings) {
cg = iterator->elem;
Expand Down
3 changes: 3 additions & 0 deletions src/lxc/cgmanager.c
Expand Up @@ -1235,6 +1235,9 @@ static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool
}

sorted_cgroup_settings = sort_cgroup_settings(cgroup_settings);
if (!sorted_cgroup_settings) {
return false;
}

lxc_list_for_each(iterator, sorted_cgroup_settings) {
char controller[100], *p;
Expand Down
8 changes: 8 additions & 0 deletions src/lxc/conf.c
Expand Up @@ -4577,11 +4577,19 @@ struct lxc_list *sort_cgroup_settings(struct lxc_list* cgroup_settings)
struct lxc_list *item = NULL;

result = malloc(sizeof(*result));
if (!result) {
ERROR("failed to allocate memory to sort cgroup settings");
return NULL;
}
lxc_list_init(result);

/*Iterate over the cgroup settings and copy them to the output list*/
lxc_list_for_each(it, cgroup_settings) {
item = malloc(sizeof(*item));
if (!item) {
ERROR("failed to allocate memory to sort cgroup settings");
return NULL;
}
item->elem = it->elem;
cg = it->elem;
if (strcmp(cg->subsystem, "memory.memsw.limit_in_bytes") == 0) {
Expand Down

0 comments on commit fac7c66

Please sign in to comment.