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 <jsafr...@redhat.com> --- src/config.c | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/config.c b/src/config.c index 38f8b92..e71a400 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; } ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel