[asterisk-dev] [asterisk-commits] tilghman: trunk r228798 - in /trunk: addons/channels/ main/ res/

Alec Davis sivad.a at paradise.net.nz
Mon Nov 9 02:58:41 CST 2009


Tilghman.
trunk/addons/cdr_mysql.c

Although changed, going by the diff attached here doesn't appear any
different?
But the commit comment suggests that it should be.

Alec
 

-----Original Message-----
From: asterisk-commits-bounces at lists.digium.com
[mailto:asterisk-commits-bounces at lists.digium.com] On Behalf Of SVN commits
to the Asterisk project
Sent: Monday, 9 November 2009 8:38 p.m.
To: asterisk-commits at lists.digium.com; svn-commits at lists.digium.com
Subject: [asterisk-commits] tilghman: trunk r228798 - in /trunk:
addons/channels/ main/ res/

Author: tilghman
Date: Mon Nov  9 01:37:52 2009
New Revision: 228798

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=228798
Log:
Fix various problems detected with Valgrind.
 * chan_console accessed pvts after deallocation.
 * cdr_mysql stored a pointer that was freed by realloc()
 * The module loader did not check usecount on shutdown, which led to
chan_iax2  reading a timer that was already unloaded.
 * The event subsystem sometimes creates an event with no IEs.  Due to a
corner  condition, the code would read beyond the memory boundary.
 * res_pktccops did not correctly check whether its monitor thread was
started.
(closes issue #16062)
 Reported by: alexanderheinz
 Patches: 
       20091109__issue16062.diff.txt uploaded by tilghman (license 14)
Tested by: tilghman

Modified:
    trunk/addons/cdr_mysql.c
    trunk/channels/chan_console.c
    trunk/main/event.c
    trunk/main/loader.c
    trunk/res/res_pktccops.c

Modified: trunk/addons/cdr_mysql.c
URL:
http://svnview.digium.com/svn/asterisk/trunk/addons/cdr_mysql.c?view=diff&re
v=228798&r1=228797&r2=228798
============================================================================
==
--- trunk/addons/cdr_mysql.c (original)
+++ trunk/addons/cdr_mysql.c Mon Nov  9 01:37:52 2009
@@ -364,15 +364,15 @@
 		return -1;
 	}
 
+	tmp = ast_variable_retrieve(cfg, category, variable);
+
+	ast_str_set(field, 0, "%s", tmp ? tmp : def);
+
 	us->str = *field;
 
 	AST_LIST_LOCK(&unload_strings);
 	AST_LIST_INSERT_HEAD(&unload_strings, us, entry);
 	AST_LIST_UNLOCK(&unload_strings);
-
-	tmp = ast_variable_retrieve(cfg, category, variable);
-
-	ast_str_set(field, 0, "%s", tmp ? tmp : def);
 
 	return 0;
 }

Modified: trunk/channels/chan_console.c
URL:
http://svnview.digium.com/svn/asterisk/trunk/channels/chan_console.c?view=di
ff&rev=228798&r1=228797&r2=228798
============================================================================
==
--- trunk/channels/chan_console.c (original)
+++ trunk/channels/chan_console.c Mon Nov  9 01:37:52 2009
@@ -1500,6 +1500,7 @@
 return_error:
 	if (pvts)
 		ao2_ref(pvts, -1);
+	pvts = NULL;
 	pvt_destructor(&globals);
 
 	return AST_MODULE_LOAD_DECLINE;

Modified: trunk/main/event.c
URL:
http://svnview.digium.com/svn/asterisk/trunk/main/event.c?view=diff&rev=2287
98&r1=228797&r2=228798
============================================================================
==
--- trunk/main/event.c (original)
+++ trunk/main/event.c Mon Nov  9 01:37:52 2009
@@ -1067,6 +1067,7 @@
 	struct ast_event *event;
 	enum ast_event_ie_type ie_type;
 	struct ast_event_ie_val *ie_val;
+	int has_ie = 0;
 	AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
 
 	/* Invalid type */
@@ -1114,6 +1115,7 @@
 
 		if (insert) {
 			AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
+			has_ie = 1;
 		}
 	}
 	va_end(ap);
@@ -1154,7 +1156,7 @@
 		}
 	}
 
-	if (!ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
+	if (has_ie && !ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
 		/* If the event is originating on this server, add the
server's
 		 * entity ID to the event. */
 		ast_event_append_ie_raw(&event, AST_EVENT_IE_EID,
&ast_eid_default, sizeof(ast_eid_default));

Modified: trunk/main/loader.c
URL:
http://svnview.digium.com/svn/asterisk/trunk/main/loader.c?view=diff&rev=228
798&r1=228797&r2=228798
============================================================================
==
--- trunk/main/loader.c (original)
+++ trunk/main/loader.c Mon Nov  9 01:37:52 2009
@@ -443,26 +443,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(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)

Modified: trunk/res/res_pktccops.c
URL:
http://svnview.digium.com/svn/asterisk/trunk/res/res_pktccops.c?view=diff&re
v=228798&r1=228797&r2=228798
============================================================================
==
--- trunk/res/res_pktccops.c (original)
+++ trunk/res/res_pktccops.c Mon Nov  9 01:37:52 2009
@@ -1446,7 +1446,7 @@
 static int unload_module(void)
 {
 	if (!ast_mutex_lock(&pktccops_lock)) {
-		if (pktccops_thread && (pktccops_thread !=
AST_PTHREADT_STOP)) {
+		if ((pktccops_thread != AST_PTHREADT_NULL) &&
(pktccops_thread != 
+AST_PTHREADT_STOP)) {
 			pthread_cancel(pktccops_thread);
 			pthread_kill(pktccops_thread, SIGURG);
 			pthread_join(pktccops_thread, NULL);


_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-commits




More information about the asterisk-dev mailing list