]> 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>
Fri, 28 Aug 2015 22:02:16 +0000 (18:02 -0400)
Signed-off-by: Kien Truong <duckientruong@gmail.com>
src/lxc/cgfs.c
src/lxc/cgmanager.c
src/lxc/conf.c

index 8aedfe4ec6027273e06979c466ec7893aa91c649..56953c5720e54941216784e855560a5e2857fcfb 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 0d1b73f363bc4da4f5bb39f4314ac30ebf272c54..a6c73f5af790fe4385e0d2cf54c43172dfc45dc9 100644 (file)
@@ -1349,6 +1349,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 39756a536328faaed12eb24c871509688c1bb525..b6e4e49be3be9e5e29f0d0dbd881b4b9f3c15e44 100644 (file)
@@ -4843,11 +4843,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) {