]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Check malloc failure when sorting cgroup settings.
authorKien Truong <duckientruong@gmail.com>
Mon, 6 Apr 2015 16:05:20 +0000 (17:05 +0100)
committerKien Truong <duckientruong@gmail.com>
Mon, 4 May 2015 23:21:59 +0000 (00:21 +0100)
Signed-off-by: Kien Truong <duckientruong@gmail.com>
src/lxc/cgfs.c
src/lxc/cgmanager.c
src/lxc/conf.c

index 0b7f99818c6044ed0efc4bd3de105ebdfce9e7ac..2ee9058ab3d7434c8dec7f96a0064d017aa39d94 100644 (file)
@@ -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;
index 51373913d0604461fad09319d60c8e4c65744047..de0bf30f3aadd890c08fbc22da92d4dff4ddcefe 100644 (file)
@@ -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;
index 64ced0f84a43a906fa3a7ec9f7fbdfda13b3b33a..9255b3488afe6edaee2fade08252ef6f1eae941a 100644 (file)
@@ -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) {