]> 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>
Wed, 1 Jul 2015 15:53:21 +0000 (11:53 -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 2ee9058ab3d7434c8dec7f96a0064d017aa39d94..fcb3cde15fdff8bd436a09971ba4bd3b3accd99a 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 de0bf30f3aadd890c08fbc22da92d4dff4ddcefe..7dddb89dedf7d2572d2442efb036d3b0845662ff 100644 (file)
@@ -1218,10 +1218,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;
@@ -1267,10 +1266,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;
 }