diff options
author | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-09-20 16:10:57 +0000 |
---|---|---|
committer | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-09-20 16:10:57 +0000 |
commit | 43a4eed03510937efa2a5c023459af42358e1786 (patch) | |
tree | ed98e7ee5cd2a8248c3d68224d04f1d998d2481b | |
parent | a35dd640cdbbe41347f01d70d63065349d0d7f77 (diff) |
Fix memory leaks in pbx_dundi, cdr_pgsql, and the configuration file parser.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@83229 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | cdr/cdr_pgsql.c | 30 | ||||
-rw-r--r-- | main/config.c | 1 | ||||
-rw-r--r-- | pbx/pbx_dundi.c | 13 |
3 files changed, 29 insertions, 15 deletions
diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c index d3813c65a..ac43e96f8 100644 --- a/cdr/cdr_pgsql.c +++ b/cdr/cdr_pgsql.c @@ -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); } diff --git a/main/config.c b/main/config.c index 380f01bea..1dc16fdc7 100644 --- a/main/config.c +++ b/main/config.c @@ -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); diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c index 7e91124af..08b9419e0 100644 --- a/pbx/pbx_dundi.c +++ b/pbx/pbx_dundi.c @@ -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); |