[asterisk-commits] rizzo: trunk r77654 - /trunk/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jul 28 19:06:35 CDT 2007


Author: rizzo
Date: Sat Jul 28 19:06:35 2007
New Revision: 77654

URL: http://svn.digium.com/view/asterisk?view=rev&rev=77654
Log:
make register_unref() return NULL so it is easy to cleanup
the original pointer while calling the function.

on passing add some comments on one of the places where it
is used, and explain why it is safe there.

again, a no-op for practical purposes.

Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=77654&r1=77653&r2=77654
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sat Jul 28 19:06:35 2007
@@ -1878,10 +1878,11 @@
 	ASTOBJ_UNREF(user, sip_destroy_user);
 }
 
-static void registry_unref(struct sip_registry *reg)
+static void *registry_unref(struct sip_registry *reg)
 {
 	ast_debug(3, "SIP Registry %s: refcount now %d\n", reg->hostname, reg->refcount - 1);
 	ASTOBJ_UNREF(reg, sip_registry_destroy);
+	return NULL;
 }
 
 /*! \brief Add object reference to SIP registry */
@@ -3531,7 +3532,7 @@
 	if (p->registry) {
 		if (p->registry->call == p)
 			p->registry->call = NULL;
-		registry_unref(p->registry);
+		p->registry = registry_unref(p->registry);
 	}
 
 	/* Unlink us from the owner if we have one */
@@ -7994,17 +7995,18 @@
 		/* Unlink us, destroy old call.  Locking is not relevant here because all this happens
 		   in the single SIP manager thread. */
 		p = r->call;
-		if (p->registry) {
-			registry_unref(p->registry);
-			p->registry = NULL;
-		}
-		r->call = NULL;
 		p->needdestroy = 1;
 		/* Pretend to ACK anything just in case */
 		__sip_pretend_ack(p); /* XXX we need p locked, not sure we have */
+
+		/* decouple the two objects */
+		/* p->registry == r, so r has 2 refs, and the unref won't take the object away */
+		if (p->registry)
+			p->registry = registry_unref(p->registry);
+		r->call = dialog_unref(r->call);
 	}
 	/* If we have a limit, stop registration and give up */
-	if (global_regattempts_max && (r->regattempts > global_regattempts_max)) {
+	if (global_regattempts_max && r->regattempts > global_regattempts_max) {
 		/* Ok, enough is enough. Don't try any more */
 		/* We could add an external notification here... 
 			steal it from app_voicemail :-) */




More information about the asterisk-commits mailing list