- 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
This commit is contained in:
Russell Bryant
2006-06-22 17:05:17 +00:00
parent cad05d819b
commit 46018d5032
11 changed files with 141 additions and 81 deletions

View File

@@ -746,9 +746,6 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c
/* Don't hold a oh323_pvt lock while we allocate a chanel */
ast_mutex_unlock(&pvt->lock);
ch = ast_channel_alloc(1);
/* Update usage counter */
ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1);
ast_update_use_count();
ast_mutex_lock(&pvt->lock);
if (ch) {
ch->tech = &oh323_tech;
@@ -803,17 +800,25 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c
ch->cid.cid_dnid = strdup(pvt->exten);
}
ast_setstate(ch, state);
/* Configure the new channel jb */
if (pvt->rtp) {
if (ast_jb_configure(ch, &global_jbconf)) {
ast_hangup(ch);
pvt->owner = NULL;
return NULL;
}
}
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(ch)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ch->name);
ast_hangup(ch);
ch = NULL;
pvt->owner = NULL;
return NULL;
}
}
/* Configure the new channel jb */
if (ch && pvt && pvt->rtp)
ast_jb_configure(ch, &global_jbconf);
/* Update usage counter */
ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1);
ast_update_use_count();
} else {
ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
}