]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: free global config_cgroup_table
authorJan Safranek <jsafrane@redhat.com>
Fri, 23 Sep 2011 11:53:13 +0000 (13:53 +0200)
committerJan Safranek <jsafrane@redhat.com>
Thu, 3 Nov 2011 09:12:46 +0000 (10:12 +0100)
To be able to call the cgroup_parse_config() several times without memory
leaks, its callers should free the memory it allocates when they don't need
it.

Signed-off-by: Jan Safranek <jsafrane@redhat.com>
src/config.c

index 38f8b9258624dfc13bb8ba5f20390ab199b8c4f2..e71a400cef1abffeca2f2755ffd919d5c0c3a94c 100644 (file)
@@ -731,6 +731,23 @@ error_out:
        return error;
 }
 
+/**
+ * Free all memory allocated during cgroup_parse_config(), namely
+ * config_cgroup_table.
+ */
+static void cgroup_free_config(void)
+{
+       int i;
+       if (config_cgroup_table) {
+               for (i = 0; i < cgroup_table_index; i++)
+                       cgroup_free_controllers(
+                                       &config_cgroup_table[i]);
+               free(config_cgroup_table);
+               config_cgroup_table = NULL;
+       }
+       config_table_index = 0;
+}
+
 static int cgroup_parse_config(const char *pathname)
 {
        int ret;
@@ -776,8 +793,7 @@ err:
        if (yyin)
                fclose(yyin);
        if (ret) {
-               free(config_cgroup_table);
-               config_cgroup_table = NULL;
+               cgroup_free_config();
        }
        return ret;
 }
@@ -841,13 +857,14 @@ int cgroup_config_load_config(const char *pathname)
        if (error)
                goto err_grp;
 
+       cgroup_free_config();
+
        return 0;
 err_grp:
        cgroup_config_destroy_groups();
 err_mnt:
        cgroup_config_unmount_controllers();
-       free(config_cgroup_table);
-       config_cgroup_table = NULL;
+       cgroup_free_config();
        return error;
 }