summaryrefslogtreecommitdiff
path: root/channels/chan_sip.c
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2006-06-22 17:05:17 +0000
committerRussell Bryant <russell@russellbryant.com>2006-06-22 17:05:17 +0000
commit46018d50321331c5d094a002f5f40540c8e7f052 (patch)
tree09e0da9c9e65e62322d7b473d2f44a59feef1bbb /channels/chan_sip.c
parentcad05d819b9da523c4ab8d8a922bd2204b07a994 (diff)
- dynamically allocate the ast_jb structure that is on the channel structure
so that channels not using a jitterbuffer don't waste as much memory - ensure that the channel drivers that use jitterbuffers can handle a failure from configuring a jitterbuffer on a new channel because of a memory allocation error - On passing through these channel drivers, configure the jitterbuffer before starting the PBX thread instead of afterwards. If the pbx fails to start for whatever reason, this would have caused a crash. - Also on passing, move the increase of the usecount to after all of the possible failure conditions in the function - fix a place where ast_update_use_count() was not called - ensure that the owner channel pointer of the channel pvt strcutures is set to NULL in failure conditions git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@35553 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r--channels/chan_sip.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 498087cdc..2dbf6ddd0 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -3648,9 +3648,6 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
if (!ast_strlen_zero(i->musicclass))
ast_string_field_set(tmp, musicclass, i->musicclass);
i->owner = tmp;
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
if (!ast_strlen_zero(i->cid_num))
@@ -3671,11 +3668,20 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
if (!ast_strlen_zero(i->callid))
pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid);
ast_setstate(tmp, state);
+ /* Configure the new channel jb */
+ if (i->rtp) {
+ if (ast_jb_configure(tmp, &global_jbconf)) {
+ ast_hangup(tmp);
+ i->owner = NULL;
+ return NULL;
+ }
+ }
if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
ast_hangup(tmp);
- tmp = NULL;
+ i->owner = NULL;
+ return NULL;
}
/* Set channel variables for this call from configuration */
for (v = i->chanvars ; v ; v = v->next)
@@ -3684,9 +3690,9 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
if (recordhistory)
append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid);
- /* Configure the new channel jb */
- if (tmp && i && i->rtp)
- ast_jb_configure(tmp, &global_jbconf);
+ ast_mutex_lock(&usecnt_lock);
+ usecnt++;
+ ast_mutex_unlock(&usecnt_lock);
return tmp;
}