Commit b0acb499 by Kien Truong Committed by Stéphane Graber

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: 's avatarKien Truong <duckientruong@gmail.com>
parent 89f25263
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment