Index: asterisk/res/res_musiconhold.c =================================================================== --- asterisk/res/res_musiconhold.c (revision 251399) +++ asterisk/res/res_musiconhold.c (working copy) @@ -1331,20 +1331,21 @@ mohclass = state->class; } } /* We don't want moh_register to unref the mohclass because we do it at the end of this function as well. * If we allowed moh_register to unref the mohclass,too, then the count would be off by one. The result would * be that the destructor would be called when the generator on the channel is deactivated. The container then * has a pointer to a freed mohclass, so any operations involving the mohclass container would result in reading * invalid memory. */ moh_register(mohclass, 0, DONT_UNREF); + mohclass = get_mohbyname(mohclass->name, 1, 0); } else { /* We don't register RT moh class, so let's init it manualy */ time(&mohclass->start); mohclass->start -= respawn_time; if (!strcasecmp(mohclass->mode, "files")) { if (!moh_scan_files(mohclass)) { mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (moh_scan_files failed)"); return -1;