Index: res/res_musiconhold.c =================================================================== --- res/res_musiconhold.c (revision 93179) +++ res/res_musiconhold.c (working copy) @@ -1556,7 +1556,31 @@ static int unload_module(void) { - return -1; + int res = 0; + struct mohclass *class = NULL; + + AST_RWLIST_RDLOCK(&mohclasses); + AST_RWLIST_TRAVERSE(&mohclasses, class, list) { + if (class->inuse > 0) { + res = -1; + break; + } + } + AST_RWLIST_UNLOCK(&mohclasses); + if (res < 0) { + ast_log(LOG_WARNING, "Unable to unload res_musiconhold due to active MOH channels\n"); + return res; + } + + ast_uninstall_music_functions(); + ast_moh_destroy(); + res = ast_unregister_application(play_moh); + res |= ast_unregister_application(wait_moh); + res |= ast_unregister_application(set_moh); + res |= ast_unregister_application(start_moh); + res |= ast_unregister_application(stop_moh); + res |= ast_cli_unregister_multiple(cli_moh, sizeof(cli_moh) / sizeof(struct ast_cli_entry)); + return res; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Music On Hold Resource",