[asterisk-commits] murf: branch murf/bug11210 r103333 - in /team/murf/bug11210: channels/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 11 23:35:06 CST 2008


Author: murf
Date: Mon Feb 11 23:35:05 2008
New Revision: 103333

URL: http://svn.digium.com/view/asterisk?view=rev&rev=103333
Log:
Another checkpoint; I only have one dialog in this test scenario that isn't destroyed after a 'stop gracefully', and a series of 'Unable to cancel schedule ID XXXX' messages, which need to be sorted out.

Modified:
    team/murf/bug11210/channels/chan_sip.c
    team/murf/bug11210/main/astobj2.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=103333&r1=103332&r2=103333
==============================================================================
--- team/murf/bug11210/channels/chan_sip.c (original)
+++ team/murf/bug11210/channels/chan_sip.c Mon Feb 11 23:35:05 2008
@@ -2392,9 +2392,9 @@
  */
 static void *dialog_unlink_all(struct sip_pvt *dialog, int lockowner, int lockdialoglist)
 {
+	dialog_ref(dialog, "Let's bump the count in the unlink so it doesn't accidentally become dead before we are done");
+
 	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) {
@@ -2420,10 +2420,11 @@
 
 	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"));
 	
-	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"));
+	if (dialog->autokillid != -1)
+		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");
-	dialog_unref(dialog, "One final decrement to counter the creation of the dialog and allow its destruction");
+	/* dialog_unref(dialog, "One final decrement to counter the creation of the dialog and allow its destruction"); this is just plain wrong. any scenario that requires this is just WRONG. */
 	return NULL;
 }
 
@@ -3033,16 +3034,14 @@
 		if (p->relatedpeer)
 			p->relatedpeer = unref_peer(p->relatedpeer, "__sip_autodestruct: unref peer p->relatedpeer");	/* Remove link to peer. If it's realtime, make sure it's gone from memory) */
 
+	/* sometimes, the unref from deleting the autokillid sched item, will
+	   free the dialog; we need to hang on a little longer and make sure it's cleaned out first */
+	dialog_ref(p, "Bump counter in autodestruct to prevent premature destructio of dialog");
 	/* Reset schedule ID */
 	if (p->autokillid != -1) {
-		int res3;
-		res3 = ast_sched_del(sched, p->autokillid);
+		AST_SCHED_DEL_UNREF(sched, p->autokillid, dialog_unref(p,"dialog unrefd because autokillid sched is being deleted"));
 		append_history(p, "CancelDestroy", "");
-		p->autokillid = -1;
-		if (!res3)
-			dialog_unref(p, "dialog unrefd because autokillid sched is being deleted");
-	}
-	
+	}
 
 	if (p->owner) {
 		ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text);
@@ -3062,6 +3061,7 @@
 		/* sip_destroy(p); */		/* Go ahead and destroy dialog. All attempts to recover is done */
 		/* sip_destroy also absorbs the reference */
 	}
+	dialog_unref(p, "UNBump counter in autodestruct to ALLOW  destructio of dialog");
 	return 0;
 }
 
@@ -9238,6 +9238,7 @@
 			ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n");
 			return 0;
 		}
+		ast_log(LOG_NOTICE,"Allocated SIP pvt dialog %p in transmit_register!\n", p);
 		
 		if (p->do_history)
 			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
@@ -9249,7 +9250,7 @@
 			/* we have what we hope is a temporary network error,
 			 * probably DNS.  We need to reschedule a registration try */
 			dialog_unlink_all(p, TRUE, TRUE);
-			p = dialog_unref(p, "unref dialog after unlink_all");
+			p = dialog_unref(p, "unref dialog after unlink_all"); /* HUH? this might be bad! */
 			if (r->timeout > -1) {
 				AST_SCHED_REPLACE(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r);
 				ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout);
@@ -9264,7 +9265,7 @@
 		ast_string_field_set(r, callid, p->callid);
 		if (r->portno) {
 			p->sa.sin_port = htons(r->portno);
-			p->recv.sin_port = htons(r->portno);
+ 			p->recv.sin_port = htons(r->portno);
 		} else 	/* Set registry port to the port set from the peer definition/srv or default */
 			r->portno = ntohs(p->sa.sin_port);
 		ast_set_flag(&p->flags[0], SIP_OUTGOING);	/* Registration is outgoing call */
@@ -12325,7 +12326,7 @@
 	   - if that's the case, wait with destruction */
 	if (dialog->needdestroy && !dialog->packets && !dialog->owner) {
 		sip_pvt_unlock(dialog);
-		dialog_unref(dialog, "needdestroy: one more refcount decrement to allow dialog to be destroyed");
+		/* no, the unlink should handle this: dialog_unref(dialog, "needdestroy: one more refcount decrement to allow dialog to be destroyed"); */
 		/* the CMP_MATCH will unlink this dialog from the dialog hash table */
 		return CMP_MATCH;
 	}
@@ -18587,6 +18588,7 @@
 	ast_set_flag(&p->flags[0], SIP_OUTGOING);
 	/* the following will decrement the refcount on p as it finishes */
 	transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->vmexten);
+	dialog_unref(p, "unref dialog ptr p just before it goes out of scope at the end of sip_send_mwi_to_peer.");
 	return 0;
 }
 
@@ -19180,7 +19182,7 @@
 		AST_SCHED_REPLACE(peer->pokeexpire, sched, 
 			peer->maxms * 2, sip_poke_noanswer, peer);
 	}
-
+	dialog_unref(p, "unref dialog at end of sip_poke_peer, obtained from sip_alloc, just before it goes out of scope");
 	return 0;
 }
 

Modified: team/murf/bug11210/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/main/astobj2.c?view=diff&rev=103333&r1=103332&r2=103333
==============================================================================
--- team/murf/bug11210/main/astobj2.c (original)
+++ team/murf/bug11210/main/astobj2.c Mon Feb 11 23:35:05 2008
@@ -169,16 +169,16 @@
 	int ret;
 	struct astobj2 *obj = INTERNAL_OBJ(user_data);
 	
+	if (obj == NULL)
+		return -1;
+
 	if (delta != 0) {
 		
 		FILE *refo = fopen(REF_FILE,"a");
-		fprintf(refo, "%p %s%d   %s:%d:%s (%s)\n", user_data, (delta<0? "":"+"), delta, file, line, funcname, tag);
+		fprintf(refo, "%p %s%d   %s:%d:%s (%s) [@%d]\n", user_data, (delta<0? "":"+"), delta, file, line, funcname, tag, obj->priv_data.ref_counter);
 		fclose(refo);
 	}
 	
-	if (obj == NULL)
-		return -1;
-
 	/* if delta is 0, just return the refcount */
 	if (delta == 0)
 		return (obj->priv_data.ref_counter);
@@ -193,9 +193,9 @@
 
 	/* this case must never happen */
 	if (current_value < 0)
-		ast_log(LOG_ERROR, "refcount %d on object %p\n", current_value, user_data);
-
-	if (current_value <= 0) { /* last reference, destroy the object */
+		ast_log(LOG_ERROR, "refcount %d on object %p -- fix your code!\n", current_value, user_data);
+
+	if (current_value == 0) { /* last reference, destroy the object */
 		if (obj->priv_data.destructor_fn != NULL) {
 			FILE *refo = fopen(REF_FILE,"a");
 			fprintf(refo, "%p **call destructor** %s:%d:%s (%s)\n", user_data, file, line, funcname, tag);
@@ -212,8 +212,11 @@
 		 * allocated. */
 		bzero(obj, sizeof(struct astobj2 *) + sizeof(void *) );
 		free(obj);
-	}
-
+	} else if (current_value < 0) {
+		FILE *refo = fopen(REF_FILE,"a");
+		fprintf(refo, "%p **Refcount 0 or less** [%d]  %s:%d:%s (%s)\n", user_data, current_value, file, line, funcname, tag);
+		fclose(refo);
+	}
 	return ret;
 }
 




More information about the asterisk-commits mailing list