From 78c79d1dd90b92f9be976e1e2052aa1fb6f31cc1 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Fri, 23 Sep 2011 13:53:13 +0200 Subject: [PATCH] libcgroup: free global config_cgroup_table 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 --- src/config.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/config.c b/src/config.c index 38f8b925..e71a400c 100644 --- a/src/config.c +++ b/src/config.c @@ -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; } -- 2.47.2