[asterisk-commits] murf: branch murf/bug11210 r102577 - /team/murf/bug11210/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 5 18:45:05 CST 2008


Author: murf
Date: Tue Feb  5 18:45:05 2008
New Revision: 102577

URL: http://svn.digium.com/view/asterisk?view=rev&rev=102577
Log:
Post reviewed and updated code now crashes. (No surprise...) Turned on refcount tracing. Found a few holes, but more remain.

Modified:
    team/murf/bug11210/channels/chan_sip.c

Modified: team/murf/bug11210/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_sip.c?view=diff&rev=102577&r1=102576&r2=102577
==============================================================================
--- team/murf/bug11210/channels/chan_sip.c (original)
+++ team/murf/bug11210/channels/chan_sip.c Tue Feb  5 18:45:05 2008
@@ -164,7 +164,7 @@
 #include "asterisk/utils.h"
 #include "asterisk/file.h"
 #include "asterisk/astobj.h"
-/* #define  REF_DEBUG 1 */
+#define  REF_DEBUG 1
 #include "asterisk/astobj2.h"
 #include "asterisk/dnsmgr.h"
 #include "asterisk/devicestate.h"
@@ -2394,6 +2394,8 @@
 {
 	ao2_t_unlink(dialogs, dialog, "unlinking dialog via ao2_unlink");
 
+	dialog_ref(dialog, "Let's bump the count in the unlink so it doesn't accidentally become dead before we are done");
+
 	/* Unlink us from the owner (channel) if we have one */
 	if (dialog->owner) {
 		if (lockowner)
@@ -2408,17 +2410,19 @@
 			dialog->registry->call = dialog_unref(dialog->registry->call, "nulling out the registry's call dialog field in unlink_all");
 		dialog->registry = registry_unref(dialog->registry, "delete dialog->registry");
 	}
-	if (dialog->initid > -1) {
-		if (ast_sched_del(sched, dialog->initid)==0)
-			dialog_unref(dialog, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr");
-		dialog->initid = -1;
-	}
+	if (dialog->stateid > -1) {
+		ast_extension_state_del(dialog->stateid, NULL);
+		dialog_unref(dialog, "removing extension_state, should unref the associated dialog ptr that was stored there.");
+		dialog->stateid = -1; /* shouldn't we 'zero' this out? */
+	}
+
+	AST_SCHED_DEL_UNREF(sched, dialog->waitid, dialog_unref(dialog, "when you delete the waitid sched, you should dec the refcount for the stored dialog ptr"));
+
+	AST_SCHED_DEL_UNREF(sched, dialog->initid, dialog_unref(dialog, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr"));
 	
-	if (dialog->autokillid > -1) {
-		dialog->autokillid = -1;
-		if (ast_sched_del(sched, dialog->autokillid)==0)
-			dialog_unref(dialog, "when you delete the autokillid sched, you should dec the refcount for the stored dialog ptr");
-	}
+	AST_SCHED_DEL_UNREF(sched, dialog->autokillid, dialog_unref(dialog, "when you delete the autokillid sched, you should dec the refcount for the stored dialog ptr"));
+
+	dialog_unref(dialog, "Let's unbump the count in the unlink so the poor pvt can disappear if it is time");
 	return NULL;
 }
 
@@ -4366,12 +4370,6 @@
 	if (p->options)
 		ast_free(p->options);
 
-	if (p->stateid > -1)
-		ast_extension_state_del(p->stateid, NULL);
-	AST_SCHED_DEL_UNREF(sched, p->initid, dialog_unref(p, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr"));
-	AST_SCHED_DEL_UNREF(sched, p->waitid, dialog_unref(p, "when you delete the waitid sched, you should dec the refcount for the stored dialog ptr"));
-	AST_SCHED_DEL_UNREF(sched, p->autokillid, dialog_unref(p, "when you delete the autokillid sched, you should dec the refcount for the stored dialog ptr"));
-
 	if (p->rtp)
 		ast_rtp_destroy(p->rtp);
 	if (p->vrtp)
@@ -4392,6 +4390,7 @@
 		if (p->stimer->st_active == TRUE && p->stimer->st_schedid > -1)
 			ast_sched_del(sched, p->stimer->st_schedid);
 		ast_free(p->stimer);
+		p->stimer = NULL;
 	}
 
 	/* Unlink us from the owner if we have one */
@@ -10436,7 +10435,6 @@
 		if (peer) {
 			ao2_t_link(peers, peer, "link peer into peer table");
 			if (peer->addr.sin_addr.s_addr) {
-				ast_log(LOG_NOTICE, "Inserted %s into peers_by_ip\n", ast_inet_ntoa(peer->addr.sin_addr));
 				ao2_t_link(peers_by_ip, peer, "link peer into peer table");
 			}
 			
@@ -17921,9 +17919,13 @@
 
 	/* Add subscription for extension state from the PBX core */
 	if (p->subscribed != MWI_NOTIFICATION && !resubscribe) {
-		if (p->stateid > -1)
+		if (p->stateid > -1) {
 			ast_extension_state_del(p->stateid, cb_extensionstate);
-		p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, p);
+			/* we need to dec the refcount, now that the extensionstate is removed */
+			dialog_unref(p, "the extensionstate containing this dialog ptr was deleted");
+		}
+		p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, p);  /* Here we go -- saving another dialog ptr in an external struct */
+		dialog_ref(p, "stored a dialog ptr in an extensionstate struct");
 	}
 
 	if (!req->ignore && p)
@@ -18755,10 +18757,7 @@
 	}
 
 	if (p->stimer->st_active == TRUE) {
-		if (ast_sched_del(sched, p->stimer->st_schedid) != 0) {
-			ast_log(LOG_WARNING, "ast_sched_del failed: %d - %s\n", p->stimer->st_schedid, p->callid);
-		}
-
+		AST_SCHED_DEL(sched, p->stimer->st_schedid);
 		ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid);
 		start_session_timer(p);
 	}
@@ -18775,7 +18774,7 @@
 
 	if (p->stimer->st_active == TRUE) {
 		p->stimer->st_active = FALSE;
-		ast_sched_del(sched, p->stimer->st_schedid);
+		AST_SCHED_DEL(sched, p->stimer->st_schedid);
 		ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid);
 	}
 }
@@ -19110,7 +19109,8 @@
 		AST_SCHED_DEL(sched, peer->pokeexpire);
 		
 		peer->lastms = 0;
-		peer->call = NULL;
+		if (peer->call)
+			peer->call = dialog_unref(peer->call, "unref dialog peer->call");
 		return 0;
 	}
 	if (peer->call) {
@@ -21465,7 +21465,6 @@
 						ast_device_state_changed("SIP/%s", peer->name);
 						ao2_t_link(peers, peer, "link peer into peer table");
 						if (peer->addr.sin_addr.s_addr) {
-							ast_log(LOG_NOTICE, "Inserted %s into peers_by_ip\n", ast_inet_ntoa(peer->addr.sin_addr));
 							ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table");
 						}
 						
@@ -21539,7 +21538,6 @@
 				if (peer) {
 					ao2_t_link(peers, peer, "link peer into peers table");
 					if (peer->addr.sin_addr.s_addr) {
-						ast_log(LOG_NOTICE, "Inserted %s into peers_by_ip\n", ast_inet_ntoa(peer->addr.sin_addr));
 						ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table");
 					}
 					unref_peer(peer, "unref_peer: reload_config: just linked peer to two tables, peers and peers_by_ip");




More information about the asterisk-commits mailing list