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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 12 09:47:33 CST 2007


Author: murf
Date: Wed Dec 12 09:47:33 2007
New Revision: 92442

URL: http://svn.digium.com/view/asterisk?view=rev&rev=92442
Log:
rearrange the sip_destroy stuff a little

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=92442&r1=92441&r2=92442
==============================================================================
--- team/murf/bug11210/channels/chan_sip.c (original)
+++ team/murf/bug11210/channels/chan_sip.c Wed Dec 12 09:47:33 2007
@@ -2082,51 +2082,33 @@
 
 static void *dialog_unlink_all(struct sip_pvt *dialog, int lockowner, int lockdialoglist)
 {
-	int rc = ao2_ref(dialog,0, "");
-	ast_log(LOG_NOTICE,"Unlink dialog %s prev refcount=%d\n", dialog->callid, rc);
-	/* Remove link from peer to subscription of MWI */
-	if (dialog->relatedpeer && dialog->relatedpeer->mwipvt) 
-		dialog->relatedpeer->mwipvt = dialog_unref(dialog->relatedpeer->mwipvt, "delete ->relatedpeer->mwipvt");
-	rc = ao2_ref(dialog,0,"");
-	ast_log(LOG_NOTICE,"Unlink dialog %s prev refcount=%d\n", dialog->callid, rc);
+	ao2_unlink(dialogs, dialog, "unlinking dialog via ao2_unlink");
+
+	/* Unlink us from the owner (channel) if we have one */
+	if (dialog->owner) {
+		if (lockowner)
+			ast_channel_lock(dialog->owner);
+		ast_debug(1, "Detaching from channel %s\n", dialog->owner->name);
+		dialog->owner->tech_pvt = dialog_unref(dialog->owner->tech_pvt,"resetting channel dialog ptr in unlink_all");
+		if (lockowner)
+			ast_channel_unlock(dialog->owner);
+	}
 	if (dialog->registry) {
 		if (dialog->registry->call == dialog)
 			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");
 	}
-	/* Unlink us from the owner (channel) if we have one */
-	if (dialog->owner) {
-		if (lockowner)
-			ast_channel_lock(dialog->owner);
-		ast_debug(1, "Detaching from %s\n", dialog->owner->name);
-		dialog->owner->tech_pvt = NULL;
-		if (lockowner)
-			ast_channel_unlock(dialog->owner);
-	}
-	rc = ao2_ref(dialog,0,"");
-	ast_log(LOG_NOTICE,"Unlink dialog %s prev refcount=%d\n", dialog->callid, rc);
-	ao2_unlink(dialogs, dialog, "unlinking dialog via ao2_unlink");
-	/* x = ao2_find(dialogs, dialog, OBJ_POINTER|OBJ_UNLINK);
-	if (!x)
-		ast_log(LOG_NOTICE,"find/unlink returns NULL\n");
-	else
-	dialog_unref(x,"remove result of ao2_find");
-	*/
-
 	if (dialog->initid > -1) {
-		ast_sched_del(sched, dialog->initid);
-		dialog_unref(dialog,"when you delete the initid sched, you should dec the refcount for the stored dialog ptr");
+		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->autokillid > -1) {
-		ast_sched_del(sched, dialog->autokillid);
-		dialog_unref(dialog,"when you delete the autokillid sched, you should dec the refcount for the stored dialog ptr");
+		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");
 		dialog->autokillid = -1;
 	}
-
-	rc = ao2_ref(dialog,0,"");
-	ast_log(LOG_NOTICE,"Unlink dialog %s prev refcount=%d\n", dialog->callid, rc);
 	return NULL;
 }
 
@@ -2728,10 +2710,11 @@
 static void sip_cancel_destroy(struct sip_pvt *p)
 {
 	if (p->autokillid > -1) {
-		ast_sched_del(sched, p->autokillid);
+		int res3 = ast_sched_del(sched, p->autokillid);
 		append_history(p, "CancelDestroy", "");
 		p->autokillid = -1;
-		dialog_unref(p,"dialog unrefd because autokillid is > -1");
+		if (res3 == 0)
+			dialog_unref(p,"dialog unrefd because autokillid is > -1");
 	}
 }
 
@@ -3939,6 +3922,16 @@
 		ast_debug(2, "This call did not properly clean up call limits. Call ID %s\n", p->callid);
 	}
 
+	/* Remove link from peer to subscription of MWI */
+	if (p->relatedpeer && p->relatedpeer->mwipvt) 
+		p->relatedpeer->mwipvt = dialog_unref(p->relatedpeer->mwipvt, "delete ->relatedpeer->mwipvt");
+
+	if (p->registry) {
+		if (p->registry->call == p)
+			p->registry->call = dialog_unref(p->registry->call,"nulling out the registry's call dialog field in unlink_all");
+		p->registry = registry_unref(p->registry, "delete p->registry");
+	}
+
 	if (dumphistory)
 		sip_dump_history(p);
 
@@ -3947,6 +3940,18 @@
 
 	if (p->stateid > -1)
 		ast_extension_state_del(p->stateid, NULL);
+
+	if (p->initid > -1) {
+		if (ast_sched_del(sched, p->initid)==0)
+			dialog_unref(p,"when you delete the initid sched, you should dec the refcount for the stored dialog ptr");
+		p->initid = -1;
+	}
+	
+	if (p->autokillid > -1) {
+		if (ast_sched_del(sched, p->autokillid)==0)
+			dialog_unref(p,"when you delete the autokillid sched, you should dec the refcount for the stored dialog ptr");
+		p->autokillid = -1;
+	}
 
 	if (p->rtp)
 		ast_rtp_destroy(p->rtp);
@@ -3978,7 +3983,7 @@
 	while((cp = p->packets)) {
 		p->packets = p->packets->next;
 		if (cp->retransid > -1)
-			ast_sched_del(sched, cp->retransid);
+			ast_sched_del(sched, cp->retransid);  /* HUH??? */
 		cp->owner = dialog_unref(cp->owner,"free cp->owner dialog before freeing the pkt");
 		ast_free(cp);
 	}
@@ -13786,8 +13791,8 @@
 	/* Acknowledge sequence number - This only happens on INVITE from SIP-call */
 	if (p->initid > -1) {
 		/* Don't auto congest anymore since we've gotten something useful back */
-		ast_sched_del(sched, p->initid);
-		dialog_unref(p,"when you delete the initid sched, you should dec the refcount for the stored dialog ptr");
+		if (ast_sched_del(sched, p->initid) == 0)
+			dialog_unref(p,"when you delete the initid sched, you should dec the refcount for the stored dialog ptr");
 		p->initid = -1;
 	}
 




More information about the asterisk-commits mailing list