]> 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)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 1 Jul 2015 15:53:17 +0000 (11:53 -0400)
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 3b2905c329ec50b5c8c0ed96ceeb6ed67b900714..aaee1fe81218a2d73b41f10443f9ad1ed1a24527 100644 (file)
@@ -4571,11 +4571,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) {