[asterisk-commits] rizzo: branch rizzo/astobj2 r47400 - /team/rizzo/astobj2/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Nov 9 15:48:49 MST 2006


Author: rizzo
Date: Thu Nov  9 16:48:48 2006
New Revision: 47400

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47400
Log:
rename a couple of fields to help fixing more reference handling with pvt.

For the time being, in same places I have put pvt_unref()
but i believe i should put sip_destroy() instead.

The places marked XXX need to be checked in trunk as well,
because i suspect pvt's (from peer->call and peer->mwipvt)
are just unreferenced but not destroyed when they should.

This would explain why, when pointing "sipp" at asterisk
with high load of calls, a lot of entries seem to remain
in "sip show channels" without expiring even after
sipp is stopped.

trunk candidate. 1.4 as well, i suspect.


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=47400&r1=47399&r2=47400
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Thu Nov  9 16:48:48 2006
@@ -1042,7 +1042,10 @@
 #define FLAG_RESPONSE (1 << 0)
 #define FLAG_FATAL (1 << 1)
 
-/*! \brief sip packet - raw format for outbound packets that are sent or scheduled for transmission */
+/*! \brief sip packet - raw format for outbound packets that are sent or scheduled for transmission
+ * Packets are linked in a list, whose head is in the sip_pvt they belong to.
+ * Each packet holds a reference to the parent sip_pvt
+ */
 struct sip_pkt {
 	struct sip_pkt *next;			/*!< Next packet in linked list */
 	int retrans;				/*!< Retransmission number */
@@ -1144,14 +1147,14 @@
 	struct sockaddr_in addr;	/*!<  IP address of peer */
 	
 	/* Qualification */
-	struct sip_pvt *call;		/*!<  Call pointer */
+	struct sip_pvt *peer_call;		/*!<  Call pointer */
 	int pokeexpire;			/*!<  When to expire poke (qualify= checking) */
 	int lastms;			/*!<  How long last response took (in ms), or -1 for no response */
 	int maxms;			/*!<  Max ms we will accept for the host to be up, 0 to not monitor */
 	struct timeval ps;		/*!<  Ping send time */
 	
 	struct sockaddr_in defaddr;	/*!<  Default IP address, used until registration */
-	struct sip_pvt *mwipvt;		/*!<  Subscription for MWI */
+	struct sip_pvt *mwi_pvt;		/*!<  Subscription for MWI */
 	int lastmsg;
 };
 
@@ -2530,11 +2533,11 @@
 		ast_log(LOG_DEBUG, "Destroying SIP peer %s\n", peer->name);
 
 	/* Delete it, it needs to disappear */
-	if (peer->call)
-		sip_destroy(peer->call);
-
-	if (peer->mwipvt) 	/* We have an active subscription, delete it */
-		sip_destroy(peer->mwipvt);
+	if (peer->peer_call)
+		sip_destroy(peer->peer_call);
+
+	if (peer->mwi_pvt) 	/* We have an active subscription, delete it */
+		sip_destroy(peer->mwi_pvt);
 
 	if (peer->chanvars) {
 		ast_variables_destroy(peer->chanvars);
@@ -3077,8 +3080,8 @@
 		ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text);
 
 	/* Remove link from peer to subscription of MWI */
-	if (p->relatedpeer && p->relatedpeer->mwipvt) 
-		p->relatedpeer->mwipvt = NULL;
+	if (p->relatedpeer && p->relatedpeer->mwi_pvt) /* XXX sip_destroy ? */
+		p->relatedpeer->mwi_pvt = pvt_unref(p->relatedpeer->mwi_pvt);
 
 	if (dumphistory)
 		sip_dump_history(p);
@@ -12331,7 +12334,9 @@
 		|| was_reachable != is_reachable;
 
 	peer->lastms = pingtime;
-	peer->call = NULL;
+	/* XXX do we need to unlink too ? */
+	if (peer->peer_call)
+		peer->peer_call = pvt_unref(peer->peer_call);
 	if (statechanged) {
 		const char *s = is_reachable ? "Reachable" : "Lagged";
 
@@ -14560,10 +14565,10 @@
 		}
 
 		p->subscribed = MWI_NOTIFICATION;
-		if (authpeer->mwipvt && authpeer->mwipvt != p)	/* Destroy old PVT if this is a new one */
+		if (authpeer->mwi_pvt && authpeer->mwi_pvt != p)	/* Destroy old PVT if this is a new one */
 			/* We only allow one subscription per peer */
-			sip_destroy(authpeer->mwipvt);
-		authpeer->mwipvt = p;		/* Link from peer to pvt */
+			sip_destroy(authpeer->mwi_pvt);
+		authpeer->mwi_pvt = p;		/* Link from peer to pvt */
 		p->relatedpeer = authpeer;	/* Link from pvt to peer */
 		/* Do not release authpeer here */
 	} else { /* At this point, Asterisk does not understand the specified event */
@@ -15054,9 +15059,9 @@
 	
 	peer->lastmsgssent = ((newmsgs << 8) | (oldmsgs));
 
-	if (peer->mwipvt) {
+	if (peer->mwi_pvt) {
 		/* Base message on subscription */
-		p = peer->mwipvt;
+		p = pvt_ref(peer->mwi_pvt);
 	} else {
 		/* Build temporary dialog for this message */
 		if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY))) 
@@ -15077,6 +15082,7 @@
 	/* Send MWI */
 	ast_set_flag(&p->flags[0], SIP_OUTGOING);
 	transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->vmexten);
+	pvt_unref(p);
 	return 0;
 }
 
@@ -15086,7 +15092,7 @@
 	time_t t = time(NULL);
 
 	if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY) &&
-	    !peer->mwipvt) {	/* We don't have a subscription */
+	    !peer->mwi_pvt) {	/* We don't have a subscription */
 		peer->lastmsgcheck = t;	/* Reset timer */
 		return FALSE;
 	}
@@ -15314,9 +15320,9 @@
 		ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE!  Last qualify: %d\n", peer->name, peer->lastms);
 		manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, -1);
 	}
-	if (peer->call)
-		sip_destroy(peer->call);
-	peer->call = NULL;
+	if (peer->peer_call)
+		sip_destroy(peer->peer_call);
+	peer->peer_call = NULL;
 	peer->lastms = -1;
 	ast_device_state_changed("SIP/%s", peer->name);
 	/* Try again quickly */
@@ -15338,15 +15344,16 @@
 			ast_sched_del(sched, peer->pokeexpire);
 		peer->lastms = 0;
 		peer->pokeexpire = -1;
-		peer->call = NULL;
+		if (peer->peer_call)	/* XXX or sip_destroy() ? */
+			peer->peer_call = pvt_unref(peer->peer_call);
 		return 0;
 	}
-	if (peer->call) {
+	if (peer->peer_call) {
 		if (sipdebug)
 			ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n");
-		sip_destroy(peer->call);
-	}
-	if (!(p = peer->call = sip_alloc(NULL, NULL, 0, SIP_OPTIONS)))
+		sip_destroy(peer->peer_call);
+	}
+	if (!(p = peer->peer_call = sip_alloc(NULL, NULL, 0, SIP_OPTIONS)))
 		return -1;
 	
 	p->sa = peer->addr;



More information about the asterisk-commits mailing list