diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-10-14 22:38:06 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-10-14 22:38:06 +0000 |
commit | 6c7d8c95dfe56152ca00cde4c7c59496b513af6a (patch) | |
tree | 96325674713833036b2bd7758905df5ccb47ca65 /res/res_indications.c | |
parent | d12237922aaa9e2273879e19453efd59a04d2503 (diff) |
Add additional memory debugging to several core APIs, and fix several memory
leaks found with these changes.
(Closes issue #13505, closes issue #13543)
Reported by: mav3rick, triccyx
Patches:
20081001__bug13505.diff.txt uploaded by Corydon76 (license 14)
Tested by: mav3rick, triccyx
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@149199 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_indications.c')
-rw-r--r-- | res/res_indications.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/res/res_indications.c b/res/res_indications.c index 7fdca5be3..7f185f319 100644 --- a/res/res_indications.c +++ b/res/res_indications.c @@ -249,6 +249,23 @@ static int handle_stopplaytones(struct ast_channel *chan, void *data) return 0; } +/* helper function to delete a tone_zone in its entirety */ +static inline void free_zone(struct ind_tone_zone* zone) +{ + while (zone->tones) { + struct ind_tone_zone_sound *tmp = zone->tones->next; + ast_free((void *)zone->tones->name); + ast_free((void *)zone->tones->data); + ast_free(zone->tones); + zone->tones = tmp; + } + + if (zone->ringcadence) + ast_free(zone->ringcadence); + + ast_free(zone); +} + /*! \brief load indications module */ static int ind_load_module(int reload) { @@ -303,6 +320,7 @@ static int ind_load_module(int reload) } if (!(tmp = ast_realloc(tones->ringcadence, (tones->nrringcadence + 1) * sizeof(int)))) { ast_config_destroy(cfg); + free_zone(tones); return -1; } tones->ringcadence = tmp; @@ -319,13 +337,14 @@ static int ind_load_module(int reload) struct ind_tone_zone* azone; if (!(azone = ast_calloc(1, sizeof(*azone)))) { ast_config_destroy(cfg); + free_zone(tones); return -1; } ast_copy_string(azone->country, country, sizeof(azone->country)); ast_copy_string(azone->alias, cxt, sizeof(azone->alias)); if (ast_register_indication_country(azone)) { ast_log(LOG_WARNING, "Unable to register indication alias at line %d.\n",v->lineno); - ast_free(tones); + free_zone(tones); } /* next item */ country = strsep(&c,","); @@ -358,17 +377,20 @@ out: v = v->next; if (tones->description[0] || tones->alias[0] || tones->tones) { if (ast_register_indication_country(tones)) { ast_log(LOG_WARNING, "Unable to register indication at line %d.\n",v->lineno); - ast_free(tones); + free_zone(tones); } - } else ast_free(tones); + } else { + free_zone(tones); + } cxt = ast_category_browse(cfg, cxt); } /* determine which country is the default */ country = ast_variable_retrieve(cfg,"general","country"); - if (!country || !*country || ast_set_indication_country(country)) + if (ast_strlen_zero(country) || ast_set_indication_country(country)) { ast_log(LOG_WARNING,"Unable to set the default country (for indication tones)\n"); + } ast_config_destroy(cfg); return 0; |