[svn-commits] rizzo: branch rizzo/astobj2 r47363 - /team/rizzo/astobj2/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Nov 9 08:14:02 MST 2006


Author: rizzo
Date: Thu Nov  9 09:14:02 2006
New Revision: 47363

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47363
Log:
more playing with refcounts.


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=47363&r1=47362&r2=47363
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Thu Nov  9 09:14:02 2006
@@ -1030,14 +1030,20 @@
 }
 #endif
 
-static void pvt_ref(struct sip_pvt *p)
+/*!
+ * when we create or delete references, make sure to use these
+ * functions so we keep track of the refcounts.
+ */
+static struct sip_pvt *pvt_ref(struct sip_pvt *p)
 {
 	ao2_ref(p, 1);
-}
-
-static void pvt_unref(struct sip_pvt *p)
+	return p;
+}
+
+static struct sip_pvt *pvt_unref(struct sip_pvt *p)
 {
 	ao2_ref(p, -1);
+	return NULL;
 }
 
 #define FLAG_RESPONSE (1 << 0)
@@ -2262,7 +2268,9 @@
 	return res;
 }
 
-/*! \brief Send SIP Request to the other part of the dialogue */
+/*! \brief Send SIP Request to the other part of the dialogue
+ * Assumes that a reference to p exists in the caller.
+ */
 static int send_request(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno)
 {
 	int res;
@@ -4570,7 +4578,7 @@
 				/* Ok, we've created a dialog, let's go and process it */
 				sip_pvt_lock(p);
 		}
-		return p;
+		return p; /* can be NULL */
 	} else if( sip_methods[intended_method].can_create == CAN_CREATE_DIALOG_UNSUPPORTED_METHOD) {
 		/* A method we do not support, let's take it on the volley */
 		transmit_response_using_temp(callid, sin, 1, intended_method, req, "501 Method Not Implemented");
@@ -7286,6 +7294,7 @@
 	char tmp[80];
 	char addr[80];
 	struct sip_pvt *p;
+	int ret;
 
 	/* exit if we are already in process with this registrar ?*/
 	if ( r == NULL || ((auth==NULL) && (r->regstate==REG_STATE_REGSENT || r->regstate==REG_STATE_AUTHSENT))) {
@@ -7298,7 +7307,7 @@
 			ast_log(LOG_WARNING, "Already have a REGISTER going on to %s@%s?? \n", r->username, r->hostname);
 			return 0;
 		} else {
-			p = r->call;
+			p = pvt_ref(r->call);	/* grab a reference */
 			make_our_tag(p->tag, sizeof(p->tag));	/* create a new local tag for every register attempt */
 			ast_string_field_free(p, theirtag);	/* forget their old tag, so we don't match tags when getting response */
 		}
@@ -7319,7 +7328,7 @@
 		if (create_addr(p, r->hostname)) {
 			/* we have what we hope is a temporary network error,
 			 * probably DNS.  We need to reschedule a registration try */
-			sip_destroy(p);
+			sip_destroy(p);	/* and the reference goes */
 			if (r->timeout > -1) {
 				ast_sched_del(sched, r->timeout);
 				r->timeout = ast_sched_add(sched, global_reg_timeout*1000, sip_reg_timeout, r);
@@ -7338,7 +7347,7 @@
 		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 */
-		r->call=p;			/* Save pointer to SIP packet */
+		r->call = pvt_ref(p);			/* Save pointer to SIP packet */
 		p->registry = ASTOBJ_REF(r);	/* Add pointer to registry in packet */
 		if (!ast_strlen_zero(r->secret))	/* Secret (password) */
 			ast_string_field_set(p, peersecret, r->secret);
@@ -7454,7 +7463,9 @@
 	r->regattempts++;	/* Another attempt */
 	if (option_debug > 3)
 		ast_verbose("REGISTER attempt %d to %s@%s\n", r->regattempts, r->username, r->hostname);
-	return send_request(p, &req, XMIT_CRITICAL, p->ocseq);
+	ret = send_request(p, &req, XMIT_CRITICAL, p->ocseq);
+	pvt_unref(p);
+	return ret;
 }
 
 /*! \brief Transmit text with SIP MESSAGE method */
@@ -8718,6 +8729,7 @@
 	- Their tag is fromtag, our tag is to-tag
 	- This means that in some transactions, totag needs to be their tag :-)
 	  depending upon the direction
+	Returns a reference, remember to release it when done XXX
 */
 static struct sip_pvt *get_sip_pvt_byid_locked(const char *callid, const char *totag, const char *fromtag) 
 {



More information about the svn-commits mailing list