--- ../lcr3/chan_lcr.c 2010-07-04 02:14:21.000000000 +0200 +++ ./chan_lcr.c 2010-07-04 04:50:22.000000000 +0200 @@ -675,9 +675,22 @@ default: newparam.setup.callerinfo.ntype = INFO_NTYPE_UNKNOWN; } + + /* If we don't lock the channel, the variable could disappear out from underneath us */ + lock_debug("A10+"); + while (ast_channel_trylock(ast)) { + DEADLOCK_AVOIDANCE(&chan_lock); + CDEBUG(call, ast, "Avoiding deadlock before reading LCR_TRANSFERCAPABILITY.\n"); + } + lock_debug("A10-"); tmp = pbx_builtin_getvar_helper(ast, "LCR_TRANSFERCAPABILITY"); - if (tmp && *tmp) - ast->transfercapability = atoi(tmp); + if (tmp && *tmp) { + tmp = ast_strdupa(tmp); + ast->transfercapability = atoi(tmp); + } + ast_channel_unlock(ast); + lock_debug("a10"); + newparam.setup.capainfo.bearer_capa = ast->transfercapability; newparam.setup.capainfo.bearer_mode = INFO_BMODE_CIRCUIT; if (call->hdlc) @@ -1692,12 +1705,17 @@ ast = call->ast; if (*p && ast) { lock_debug("A1+"); -// ast_channel_lock(ast); + while (ast_channel_trylock(ast)) { + /* Avoid deadlock by pausing and trying again */ + DEADLOCK_AVOIDANCE(&chan_lock); + CDEBUG(call, ast, "Avoiding deadlock before sending to Asterisk.\n"); + } + CDEBUG(call, ast, "Channel clear to send to Asterisk.\n"); lock_debug("A1-"); while(*p) { switch (*p) { case 'T': - CDEBUG(call, ast, "Sending queued PROGRESS to Asterisk.\n"); + ast_queue_control(ast, AST_CONTROL_PROGRESS); break; case 'P': @@ -1749,7 +1767,7 @@ p++; } call->queue_string[0] = '\0'; -// ast_channel_unlock(ast); + ast_channel_unlock(ast); lock_debug("a1"); } call = call->next;