From 03a5e8a729a4160ddbb357146d3852496b7605a4 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 14 Aug 2012 10:10:46 +0200 Subject: [PATCH] core: free data before removing config file/section/option from lists (remove warning in valgrind about blocks still reachable) --- src/core/wee-config-file.c | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index aecb438b5..646d85485 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -2441,6 +2441,9 @@ config_file_option_free (struct t_config_option *option) ptr_section = option->section; + /* free data */ + config_file_option_free_data (option); + /* remove option from section */ if (ptr_section) { @@ -2458,9 +2461,6 @@ config_file_option_free (struct t_config_option *option) ptr_section->options = new_options; } - /* free data */ - config_file_option_free_data (option); - free (option); } @@ -2495,7 +2495,12 @@ config_file_section_free (struct t_config_section *section) ptr_config = section->config_file; - /* remove section */ + /* free data */ + config_file_section_free_options (section); + if (section->name) + free (section->name); + + /* remove section from list */ if (ptr_config->last_section == section) ptr_config->last_section = section->prev_section; if (section->prev_section) @@ -2509,11 +2514,6 @@ config_file_section_free (struct t_config_section *section) if (section->next_section) (section->next_section)->prev_section = section->prev_section; - /* free data */ - config_file_section_free_options (section); - if (section->name) - free (section->name); - free (section); ptr_config->sections = new_sections; @@ -2531,7 +2531,17 @@ config_file_free (struct t_config_file *config_file) if (!config_file) return; - /* remove configuration file */ + /* free data */ + while (config_file->sections) + { + config_file_section_free (config_file->sections); + } + if (config_file->name) + free (config_file->name); + if (config_file->filename) + free (config_file->filename); + + /* remove configuration file from list */ if (last_config_file == config_file) last_config_file = config_file->prev_config; if (config_file->prev_config) @@ -2545,16 +2555,6 @@ config_file_free (struct t_config_file *config_file) if (config_file->next_config) (config_file->next_config)->prev_config = config_file->prev_config; - /* free data */ - while (config_file->sections) - { - config_file_section_free (config_file->sections); - } - if (config_file->name) - free (config_file->name); - if (config_file->filename) - free (config_file->filename); - free (config_file); config_files = new_config_files;