summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2008-11-01 20:41:38 +0000
committerRussell Bryant <russell@russellbryant.com>2008-11-01 20:41:38 +0000
commit1fef0f63bbbde9530837995c8790b839f73b74e7 (patch)
tree94795d943a8b61e226e8a6026e70a22701956cf5
parent0327f37d340aa06030cd7e265a462f294317a91e (diff)
Ensure that the sip_pvt properly has its refcount incremented when the scheduler holds
a reference to it for session timer processing. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@153362 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--channels/chan_sip.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index f5d8180fc..02061bf18 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -4843,8 +4843,10 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist)
/* 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;
}
@@ -20518,7 +20520,8 @@ static void restart_session_timer(struct sip_pvt *p)
}
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);
}
@@ -20535,7 +20538,8 @@ static void stop_session_timer(struct sip_pvt *p)
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);
}
}
@@ -20549,8 +20553,10 @@ static void start_session_timer(struct sip_pvt *p)
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);
@@ -20562,23 +20568,21 @@ static int proc_session_timer(const void *vp)
{
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) {
@@ -20594,28 +20598,40 @@ static int proc_session_timer(const void *vp)
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);
+ ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV);
+ ast_channel_unlock(p->owner);
}
}
- return 1;
+
+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;
}