]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveconf, config: Free all memory at deinit
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 10 Apr 2016 11:39:22 +0000 (14:39 +0300)
committerGitLab <gitlab@git.dovecot.net>
Tue, 12 Apr 2016 13:08:18 +0000 (16:08 +0300)
src/config/config-parser.c
src/config/config-parser.h
src/config/doveconf.c
src/config/main.c

index cb7910d8fe8db257927c70ba0d5ff5611f779a1c..fa779c623d639dadd4b5aedc8b1c764c20bee8ea 100644 (file)
@@ -31,6 +31,8 @@
 #define DNS_LOOKUP_TIMEOUT_SECS 30
 #define DNS_LOOKUP_WARN_SECS 5
 
+ARRAY_DEFINE_TYPE(setting_parser_info_p, const struct setting_parser_info *);
+
 static const enum settings_parser_flags settings_parser_flags =
        SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS |
        SETTINGS_PARSER_FLAG_TRACK_CHANGES;
@@ -42,6 +44,9 @@ void (*hook_config_parser_begin)(struct config_parser_context *ctx);
 int (*hook_config_parser_end)(struct config_parser_context *ctx,
                              const char **error_r);
 
+static ARRAY_TYPE(service_settings) services_free_at_deinit = ARRAY_INIT;
+static ARRAY_TYPE(setting_parser_info_p) roots_free_at_deinit = ARRAY_INIT;
+
 static const char *info_type_name_find(const struct setting_parser_info *info)
 {
        unsigned int i;
@@ -1007,7 +1012,7 @@ void config_parse_load_modules(void)
        struct module_dir_load_settings mod_set;
        struct module *m;
        const struct setting_parser_info **roots;
-       ARRAY(const struct setting_parser_info *) new_roots;
+       ARRAY_TYPE(setting_parser_info_p) new_roots;
        ARRAY_TYPE(service_settings) new_services;
        struct service_settings *const *services, *service_set;
        unsigned int i, count;
@@ -1046,6 +1051,9 @@ void config_parse_load_modules(void)
                        array_append(&new_roots, &all_roots[i], 1);
                array_append_zero(&new_roots);
                all_roots = array_idx(&new_roots, 0);
+               roots_free_at_deinit = new_roots;
+       } else {
+               array_free(&new_roots);
        }
        if (array_count(&new_services) > 0) {
                /* module added new services. update the defaults. */
@@ -1053,6 +1061,9 @@ void config_parse_load_modules(void)
                for (i = 0; i < count; i++)
                        array_append(&new_services, &services[i], 1);
                *default_services = new_services;
+               services_free_at_deinit = new_services;
+       } else {
+               array_free(&new_services);
        }
 }
 
@@ -1102,3 +1113,11 @@ bool config_module_want_parser(struct config_module_parser *parsers,
        }
        return FALSE;
 }
+
+void config_parser_deinit(void)
+{
+       if (array_is_created(&services_free_at_deinit))
+               array_free(&services_free_at_deinit);
+       if (array_is_created(&roots_free_at_deinit))
+               array_free(&roots_free_at_deinit);
+}
index 98cb9cb585e68ec41873e9f9e308ebead583dbb5..e0a0a5bea3329eb5f33be67f18a46509c554f67e 100644 (file)
@@ -28,5 +28,6 @@ bool config_module_want_parser(struct config_module_parser *parsers,
                               const char *const *modules,
                               const struct setting_parser_info *root)
        ATTR_NULL(2);
+void config_parser_deinit(void);
 
 #endif
index 1df9201de2abb6e57ccdfd7bfc616392911e93f3..095a78840f59c2e7ca1754bd016970c1bda94730 100644 (file)
@@ -881,6 +881,7 @@ int main(int argc, char *argv[])
 
        config_filter_deinit(&config_filter);
        module_dir_unload(&modules);
+       config_parser_deinit();
        master_service_deinit(&master_service);
         return 0;
 }
index c5ccc52b246c00c3e00ff921098f4e6cfd2bfe5c..2a44731cda9bebad4a9941b556787316ccd096fe 100644 (file)
@@ -42,6 +42,7 @@ int main(int argc, char *argv[])
 
        config_filter_deinit(&config_filter);
        module_dir_unload(&modules);
+       config_parser_deinit();
        master_service_deinit(&master_service);
         return 0;
 }