[svn-commits] tilghman: branch 1.4 r248012 - in /branches/1.4: ./ main/loader.c
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Feb 19 13:11:50 CST 2010
Author: tilghman
Date: Fri Feb 19 13:11:45 2010
New Revision: 248012
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=248012
Log:
Backport crash fix from trunk to 1.4, whereby 'core show gracefully' could crash Asterisk.
(closes issue #16470)
Reported by: kjotte
Modified:
branches/1.4/ (props changed)
branches/1.4/main/loader.c
Propchange: branches/1.4/
------------------------------------------------------------------------------
svn:mergeinfo = /trunk:228798
Modified: branches/1.4/main/loader.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/main/loader.c?view=diff&rev=248012&r1=248011&r2=248012
==============================================================================
--- branches/1.4/main/loader.c (original)
+++ branches/1.4/main/loader.c Fri Feb 19 13:11:45 2010
@@ -449,26 +449,39 @@
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);
+
+ /*!\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);
-
- 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);
- }
}
int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode force)
More information about the svn-commits
mailing list