[asterisk-commits] russell: branch 1.6.1 r153363 - in /branches/1.6.1: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Nov 1 15:47:32 CDT 2008


Author: russell
Date: Sat Nov  1 15:47:31 2008
New Revision: 153363

URL: http://svn.digium.com/view/asterisk?view=rev&rev=153363
Log:
Merged revisions 153362 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
r153362 | russell | 2008-11-01 15:41:38 -0500 (Sat, 01 Nov 2008) | 3 lines

Ensure that the sip_pvt properly has its refcount incremented when the scheduler holds
a reference to it for session timer processing.

........

Modified:
    branches/1.6.1/   (props changed)
    branches/1.6.1/channels/chan_sip.c

Propchange: branches/1.6.1/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.1/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/channels/chan_sip.c?view=diff&rev=153363&r1=153362&r2=153363
==============================================================================
--- branches/1.6.1/channels/chan_sip.c (original)
+++ branches/1.6.1/channels/chan_sip.c Sat Nov  1 15:47:31 2008
@@ -4644,8 +4644,10 @@
 
 	/* Destroy Session-Timers if allocated */
 	if (p->stimer) {
-		if (p->stimer->st_active == TRUE && p->stimer->st_schedid > -1)
-			AST_SCHED_DEL(sched, p->stimer->st_schedid);
+		if (p->stimer->st_active == TRUE && p->stimer->st_schedid > -1) {
+			AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid,
+					dialog_unref(p, "removing session timer ref"));
+		}
 		ast_free(p->stimer);
 		p->stimer = NULL;
 	}
@@ -19810,7 +19812,8 @@
 	}
 
 	if (p->stimer->st_active == TRUE) {
-		AST_SCHED_DEL(sched, p->stimer->st_schedid);
+		AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid,
+				dialog_unref(p, "Removing session timer ref"));
 		ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid);
 		start_session_timer(p);
 	}
@@ -19827,7 +19830,8 @@
 
 	if (p->stimer->st_active == TRUE) {
 		p->stimer->st_active = FALSE;
-		AST_SCHED_DEL(sched, p->stimer->st_schedid);
+		AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid,
+				dialog_unref(p, "removing session timer ref"));
 		ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid);
 	}
 }
@@ -19841,8 +19845,10 @@
 		return;
 	}
 
-	p->stimer->st_schedid  = ast_sched_add(sched, p->stimer->st_interval * 1000 / 2, proc_session_timer, p);
+	p->stimer->st_schedid  = ast_sched_add(sched, p->stimer->st_interval * 1000 / 2, proc_session_timer, 
+			dialog_ref(p, "adding session timer ref"));
 	if (p->stimer->st_schedid < 0) {
+		dialog_unref(p, "removing session timer ref");
 		ast_log(LOG_ERROR, "ast_sched_add failed.\n");
 	}
 	ast_debug(2, "Session timer started: %d - %s\n", p->stimer->st_schedid, p->callid);
@@ -19854,23 +19860,21 @@
 {
 	struct sip_pvt *p = (struct sip_pvt *) vp;
 	int sendreinv = FALSE;
+	int res = 0;
 
 	if (!p->stimer) {
 		ast_log(LOG_WARNING, "Null stimer in proc_session_timer - %s\n", p->callid);
-		return 0;
+		goto return_unref;
 	}
 
 	ast_debug(2, "Session timer expired: %d - %s\n", p->stimer->st_schedid, p->callid);
 
 	if (!p->owner) {
-		if (p->stimer->st_active == TRUE) {
-			stop_session_timer(p);
-		}
-		return 0;
+		goto return_unref;
 	}
 
 	if ((p->stimer->st_active != TRUE) || (p->owner->_state != AST_STATE_UP)) {
-		return 0;
+		goto return_unref;
 	}
 
 	switch (p->stimer->st_ref) {
@@ -19886,28 +19890,40 @@
 		break;
 	default:
 		ast_log(LOG_ERROR, "Unknown session refresher %d\n", p->stimer->st_ref);
-		return -1;
+		goto return_unref;
 	}
 
 	if (sendreinv == TRUE) {
+		res = 1;
 		transmit_reinvite_with_sdp(p, FALSE, TRUE);
 	} else {
 		p->stimer->st_expirys++;
 		if (p->stimer->st_expirys >= 2) {
 			ast_log(LOG_WARNING, "Session-Timer expired - %s\n", p->callid);
-			stop_session_timer(p);
 
 			while (p->owner && ast_channel_trylock(p->owner)) {
 				sip_pvt_unlock(p);
 				usleep(1);
 				sip_pvt_lock(p);
-          		}
-
-           		ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV);
-           		ast_channel_unlock(p->owner);
-		}
-	}
-	return 1;
+			}
+
+			ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV);
+			ast_channel_unlock(p->owner);
+		}
+	}
+
+return_unref:
+	if (!res) {
+		/* An error occurred.  Stop session timer processing */
+		p->stimer->st_schedid = -1;
+		stop_session_timer(p);
+		
+		/* If we are not asking to be rescheduled, then we need to release our
+		 * reference to the dialog. */
+		dialog_unref(p, "removing session timer ref");
+	}
+
+	return res;
 }
 
 




More information about the asterisk-commits mailing list