Skip to content

Commit

Permalink
Properly free memory of sorted cgroup settings
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
kien-truong committed May 4, 2015
1 parent fac7c66 commit 365d180
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/lxc/cgfs.c
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/lxc/cgmanager.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 365d180

Please sign in to comment.