aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-19 19:11:45 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-19 19:11:45 +0000
commit1fbe34f8b1f9e7b6ad55d475e1016135641d18f2 (patch)
tree7a54d908b2f386f57e356633347190d81d210cb7 /main
parentf119881325a4be594732ab17a3b4fa5e261ccce9 (diff)
Backport crash fix from trunk to 1.4, whereby 'core show gracefully' could crash Asterisk.
(closes issue #16470) Reported by: kjotte git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@248012 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/loader.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/main/loader.c b/main/loader.c
index 98284b178..5d79e5371 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -449,26 +449,39 @@ static struct ast_module *load_dynamic_module(const char *resource_in, enum modu
void ast_module_shutdown(void)
{
struct ast_module *mod;
- AST_LIST_HEAD_NOLOCK_STATIC(local_module_list, ast_module);
-
- /* We have to call the unload() callbacks in reverse order that the modules
- * exist in the module list so it is the reverse order of how they were
- * loaded. */
+ int somethingchanged = 1, final = 0;
AST_LIST_LOCK(&module_list);
- while ((mod = AST_LIST_REMOVE_HEAD(&module_list, entry)))
- AST_LIST_INSERT_HEAD(&local_module_list, mod, entry);
- AST_LIST_UNLOCK(&module_list);
- while ((mod = AST_LIST_REMOVE_HEAD(&local_module_list, entry))) {
- if (mod->info->unload)
- mod->info->unload();
- /* Since this should only be called when shutting down "gracefully",
- * all channels should be down before we get to this point, meaning
- * there will be no module users left. */
- AST_LIST_HEAD_DESTROY(&mod->users);
- free(mod);
- }
+ /*!\note Some resources, like timers, are started up dynamically, and thus
+ * may be still in use, even if all channels are dead. We must therefore
+ * check the usecount before asking modules to unload. */
+ do {
+ if (!somethingchanged) {
+ /*!\note If we go through the entire list without changing
+ * anything, ignore the usecounts and unload, then exit. */
+ final = 1;
+ }
+
+ /* Reset flag before traversing the list */
+ somethingchanged = 0;
+
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) {
+ if (!final && mod->usecount) {
+ continue;
+ }
+ AST_LIST_REMOVE_CURRENT(&module_list, entry);
+ if (mod->info->unload) {
+ mod->info->unload();
+ }
+ AST_LIST_HEAD_DESTROY(&mod->users);
+ free(mod);
+ somethingchanged = 1;
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ } while (somethingchanged && !final);
+
+ AST_LIST_UNLOCK(&module_list);
}
int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode force)