Fix memory leak in features_config.c
authorMark Michelson <mmichelson@digium.com>
Thu, 13 Jun 2013 18:17:13 +0000 (18:17 +0000)
committerMark Michelson <mmichelson@digium.com>
Thu, 13 Jun 2013 18:17:13 +0000 (18:17 +0000)
The options should not be registered multiple times. Instead, the configuration just needs
to be reprocessed by the config framework. This also exposed that we were not properly telling
the config framework to treat the configuration processing with the "reload" semantics when
a reload occurred. Both of these errors are fixed now.

Thanks to Richard Mudgett for discovering the leak.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391676 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/features_config.c

index 163c37d..6d5cf1a 100644 (file)
@@ -1345,9 +1345,9 @@ static struct ast_custom_function featuremap_function = {
        .write = featuremap_write
 };
 
-static int load_config(int reload)
+static int load_config(void)
 {
-       if (!reload && aco_info_init(&cfg_info)) {
+       if (aco_info_init(&cfg_info)) {
                ast_log(LOG_ERROR, "Unable to initialize configuration info for features\n");
                return -1;
        }
@@ -1441,10 +1441,8 @@ static int load_config(int reload)
 
        if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
                ast_log(LOG_ERROR, "Failed to process features.conf configuration!\n");
-               if (!reload) {
-                       aco_info_destroy(&cfg_info);
-                       ao2_global_obj_release(globals);
-               }
+               aco_info_destroy(&cfg_info);
+               ao2_global_obj_release(globals);
                return -1;
        }
 
@@ -1559,14 +1557,17 @@ void ast_features_config_shutdown(void)
 
 int ast_features_config_reload(void)
 {
-       return load_config(1);
+       if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
+               return -1;
+       }
+       return load_config();
 }
 
 int ast_features_config_init(void)
 {
        int res;
 
-       res = load_config(0);
+       res = load_config();
        res |= __ast_custom_function_register(&feature_function, NULL);
        res |= __ast_custom_function_register(&featuremap_function, NULL);
        res |= ast_cli_register_multiple(cli_features_config, ARRAY_LEN(cli_features_config));