]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Properly free memory of sorted cgroup settings
authorKien Truong <duckientruong@gmail.com>
Mon, 6 Apr 2015 16:20:43 +0000 (17:20 +0100)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 28 Aug 2015 22:02:16 +0000 (18:02 -0400)
We need to use lxc_list_for_each_safe, otherwise de-allocation
will fail with a list size bigger than 2. The pointer to the head
of the list also need freeing after we've freed all other elements
of the list.

Signed-off-by: Kien Truong <duckientruong@gmail.com>
src/lxc/cgfs.c
src/lxc/cgmanager.c

index 56953c5720e54941216784e855560a5e2857fcfb..6a76fabf311f880963b3bab60caf7d4ef873252b 100644 (file)
@@ -1886,9 +1886,8 @@ static int do_cgroup_set(const char *cgroup_path, const char *sub_filename,
 static int do_setup_cgroup_limits(struct cgfs_data *d,
                           struct lxc_list *cgroup_settings, bool do_devices)
 {
-       struct lxc_list *iterator;
+       struct lxc_list *iterator, *sorted_cgroup_settings, *next;
        struct lxc_cgroup *cg;
-       struct lxc_list *sorted_cgroup_settings;
        int ret = -1;
 
        if (lxc_list_empty(cgroup_settings))
@@ -1922,10 +1921,11 @@ static int do_setup_cgroup_limits(struct cgfs_data *d,
        ret = 0;
        INFO("cgroup has been setup");
 out:
-       lxc_list_for_each(iterator, sorted_cgroup_settings) {
+       lxc_list_for_each_safe(iterator, sorted_cgroup_settings, next) {
                lxc_list_del(iterator);
                free(iterator);
        }
+       free(sorted_cgroup_settings);
        return ret;
 }
 
index a6c73f5af790fe4385e0d2cf54c43172dfc45dc9..ead8cb52f352c49bfce8d7463ef447b4a11c7218 100644 (file)
@@ -1332,10 +1332,9 @@ static bool cgm_unfreeze(void *hdata)
 static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool do_devices)
 {
        struct cgm_data *d = hdata;
-       struct lxc_list *iterator;
+       struct lxc_list *iterator, *sorted_cgroup_settings, *next;
        struct lxc_cgroup *cg;
        bool ret = false;
-       struct lxc_list *sorted_cgroup_settings;
 
        if (lxc_list_empty(cgroup_settings))
                return true;
@@ -1381,10 +1380,11 @@ static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool
        ret = true;
        INFO("cgroup limits have been setup");
 out:
-       lxc_list_for_each(iterator, sorted_cgroup_settings) {
+       lxc_list_for_each_safe(iterator, sorted_cgroup_settings, next) {
                lxc_list_del(iterator);
                free(iterator);
        }
+       free(sorted_cgroup_settings);
        cgm_dbus_disconnect();
        return ret;
 }