From: Kien Truong Date: Mon, 6 Apr 2015 16:20:43 +0000 (+0100) Subject: Properly free memory of sorted cgroup settings X-Git-Tag: lxc-1.1.3~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0acb49902775fbc3a8286a52292e5b6c81e3b3b;p=thirdparty%2Flxc.git Properly free memory of sorted cgroup settings 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 --- diff --git a/src/lxc/cgfs.c b/src/lxc/cgfs.c index 2ee9058ab..fcb3cde15 100644 --- a/src/lxc/cgfs.c +++ b/src/lxc/cgfs.c @@ -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; } diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c index de0bf30f3..7dddb89de 100644 --- a/src/lxc/cgmanager.c +++ b/src/lxc/cgmanager.c @@ -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; }