Index: channels/chan_dahdi.c =================================================================== --- channels/chan_dahdi.c (revision 266682) +++ channels/chan_dahdi.c (working copy) @@ -17157,8 +17157,8 @@ { struct ast_config *cfg, *ucfg; struct ast_variable *v; - struct dahdi_chan_conf base_conf = dahdi_chan_conf_default(); - struct dahdi_chan_conf conf; + struct dahdi_chan_conf base_conf = dahdi_chan_conf_default(); + struct dahdi_chan_conf conf; struct ast_flags config_flags = { reload == 1 ? CONFIG_FLAG_FILEUNCHANGED : 0 }; const char *cat; int res; @@ -17274,6 +17274,7 @@ v = ast_variable_browse(cfg, "channels"); if ((res = process_dahdi(&base_conf, "", v, reload, 0))) { + ast_variables_destroy(base_conf.chan.vars); ast_mutex_unlock(&iflock); ast_config_destroy(cfg); if (ucfg) { @@ -17284,6 +17285,8 @@ /* Now get configuration from all normal sections in chan_dahdi.conf: */ for (cat = ast_category_browse(cfg, NULL); cat ; cat = ast_category_browse(cfg, cat)) { + struct ast_variable *v, *p; + /* [channels] and [trunkgroups] are used. Let's also reserve * [globals] and [general] for future use */ @@ -17295,8 +17298,20 @@ } memcpy(&conf, &base_conf, sizeof(conf)); + /* Fix shallow copy of base_conf.chan.vars */ + for (v = base_conf.chan.vars, p = NULL; v; v = v->next) { + struct ast_variable *next = ast_variable_new(v->name, v->value, ""); + if (p) { + p->next = next; + } else { + conf.chan.vars = p; + } + p = next; + } if ((res = process_dahdi(&conf, cat, ast_variable_browse(cfg, cat), reload, PROC_DAHDI_OPT_NOCHAN))) { + ast_variables_destroy(base_conf.chan.vars); + ast_variables_destroy(conf.chan.vars); ast_mutex_unlock(&iflock); ast_config_destroy(cfg); if (ucfg) { @@ -17304,6 +17319,10 @@ } return res; } + + /* Destroy local copy on every iteration */ + ast_variables_destroy(conf.chan.vars); + conf.chan.vars = NULL; } ast_config_destroy(cfg); @@ -17314,6 +17333,8 @@ process_dahdi(&base_conf, "", ast_variable_browse(ucfg, "general"), 1, 0); for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) { + struct ast_variable *v, *p; + if (!strcasecmp(cat, "general")) { continue; } @@ -17325,12 +17346,28 @@ } memcpy(&conf, &base_conf, sizeof(conf)); + /* Fix shallow copy of base_conf.chan.vars */ + for (v = base_conf.chan.vars, p = NULL; v; v = v->next) { + struct ast_variable *next = ast_variable_new(v->name, v->value, ""); + if (p) { + p->next = next; + } else { + conf.chan.vars = p; + } + p = next; + } if ((res = process_dahdi(&conf, cat, ast_variable_browse(ucfg, cat), reload, PROC_DAHDI_OPT_NOCHAN | PROC_DAHDI_OPT_NOWARN))) { + ast_variables_destroy(base_conf.chan.vars); + ast_variables_destroy(conf.chan.vars); ast_config_destroy(ucfg); ast_mutex_unlock(&iflock); return res; } + + /* Destroy local copy on every iteration */ + ast_variables_destroy(conf.chan.vars); + conf.chan.vars = NULL; } ast_config_destroy(ucfg); } @@ -17379,6 +17416,7 @@ #endif /* And start the monitor for the first time */ restart_monitor(); + ast_variables_destroy(base_conf.chan.vars); return 0; }