Fix memory leaks in pbx_dundi, cdr_pgsql, and the configuration file parser.
authorJoshua Colp <jcolp@digium.com>
Thu, 20 Sep 2007 16:10:57 +0000 (16:10 +0000)
committerJoshua Colp <jcolp@digium.com>
Thu, 20 Sep 2007 16:10:57 +0000 (16:10 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@83229 65c4cc65-6c06-0410-ace0-fbb531ad65f3

cdr/cdr_pgsql.c
main/config.c
pbx/pbx_dundi.c

index d3813c6..ac43e96 100644 (file)
@@ -216,8 +216,10 @@ static int config_module(int reload)
        } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
                return 0;
 
-       if (!(var = ast_variable_browse(cfg, "global")))
+       if (!(var = ast_variable_browse(cfg, "global"))) {
+               ast_config_destroy(cfg);
                return 0;
+       }
 
        if (!(tmp = ast_variable_retrieve(cfg, "global", "hostname"))) {
                ast_log(LOG_WARNING, "PostgreSQL server hostname not specified.  Assuming unix socket connection\n");
@@ -226,8 +228,10 @@ static int config_module(int reload)
 
        if (pghostname)
                ast_free(pghostname);
-       if (!(pghostname = ast_strdup(tmp)))
+       if (!(pghostname = ast_strdup(tmp))) {
+               ast_config_destroy(cfg);
                return -1;
+       }
 
        if (!(tmp = ast_variable_retrieve(cfg, "global", "dbname"))) {
                ast_log(LOG_WARNING,"PostgreSQL database not specified.  Assuming asterisk\n");
@@ -236,8 +240,10 @@ static int config_module(int reload)
 
        if (pgdbname)
                ast_free(pgdbname);
-       if (!(pgdbname = ast_strdup(tmp)))
+       if (!(pgdbname = ast_strdup(tmp))) {
+               ast_config_destroy(cfg);
                return -1;
+       }
 
        if (!(tmp = ast_variable_retrieve(cfg, "global", "user"))) {
                ast_log(LOG_WARNING,"PostgreSQL database user not specified.  Assuming asterisk\n");
@@ -246,8 +252,10 @@ static int config_module(int reload)
 
        if (pgdbuser)
                ast_free(pgdbuser);
-       if (!(pgdbuser = ast_strdup(tmp)))
+       if (!(pgdbuser = ast_strdup(tmp))) {
+               ast_config_destroy(cfg);
                return -1;
+       }
 
        if (!(tmp = ast_variable_retrieve(cfg, "global", "password"))) {
                ast_log(LOG_WARNING,"PostgreSQL database password not specified.  Assuming blank\n");
@@ -256,8 +264,10 @@ static int config_module(int reload)
 
        if (pgpassword)
                ast_free(pgpassword);
-       if (!(pgpassword = ast_strdup(tmp)))
+       if (!(pgpassword = ast_strdup(tmp))) {
+               ast_config_destroy(cfg);
                return -1;
+       }
 
        if (!(tmp = ast_variable_retrieve(cfg,"global","port"))) {
                ast_log(LOG_WARNING,"PostgreSQL database port not specified.  Using default 5432.\n");
@@ -266,8 +276,10 @@ static int config_module(int reload)
 
        if (pgdbport)
                ast_free(pgdbport);
-       if (!(pgdbport = ast_strdup(tmp)))
+       if (!(pgdbport = ast_strdup(tmp))) {
+               ast_config_destroy(cfg);
                return -1;
+       }
 
        if (!(tmp = ast_variable_retrieve(cfg, "global", "table"))) {
                ast_log(LOG_WARNING,"CDR table not specified.  Assuming cdr\n");
@@ -276,8 +288,10 @@ static int config_module(int reload)
 
        if (table)
                ast_free(table);
-       if (!(table = ast_strdup(tmp)))
+       if (!(table = ast_strdup(tmp))) {
+               ast_config_destroy(cfg);
                return -1;
+       }
 
        if (option_debug) {
                if (ast_strlen_zero(pghostname))
@@ -302,6 +316,8 @@ static int config_module(int reload)
                connected = 0;
        }
 
+       ast_config_destroy(cfg);
+
        return ast_cdr_register(name, ast_module_info->description, pgsql_log);
 }
 
index 380f01b..1dc16fd 100644 (file)
@@ -765,6 +765,7 @@ void ast_config_destroy(struct ast_config *cfg)
                ast_variables_destroy(cat->root);
                catn = cat;
                cat = cat->next;
+               ast_free(catn->file);
                ast_free(catn);
        }
        ast_free(cfg);
index 7e91124..08b9419 100644 (file)
@@ -4635,19 +4635,16 @@ static int set_config(char *config_file, struct sockaddr_in* sin, int reload)
        int globalpcmodel = 0;
        dundi_eid testeid;
 
-       if ((cfg = ast_config_load(config_file, config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+       if (!(cfg = ast_config_load(config_file, config_flags))) {
+               ast_log(LOG_ERROR, "Unable to load config %s\n", config_file);
+               return -1;
+       } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
                return 0;
 
        dundi_ttl = DUNDI_DEFAULT_TTL;
        dundi_cache_time = DUNDI_DEFAULT_CACHE_TIME;
        any_peer = NULL;
-       
-       cfg = ast_config_load(config_file, config_flags);
-       
-       if (!cfg) {
-               ast_log(LOG_ERROR, "Unable to load config %s\n", config_file);
-               return -1;
-       }
+
        ipaddr[0] = '\0';
        if (!gethostname(hn, sizeof(hn)-1)) {
                hp = ast_gethostbyname(hn, &he);