Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 47221) +++ channels/chan_sip.c (working copy) @@ -10748,6 +10748,7 @@ { struct ast_channel *c=NULL; int res; + int attempttransferres = 0; struct ast_channel *transfer_to; char *transfercontext = NULL; @@ -10767,12 +10768,14 @@ if (!ignore) { if (p->refer_call) { ast_log(LOG_DEBUG,"202 Accepted (supervised)\n"); - attempt_transfer(p, p->refer_call); - if (p->refer_call->owner) - ast_mutex_unlock(&p->refer_call->owner->lock); - ast_mutex_unlock(&p->refer_call->lock); - p->refer_call = NULL; - ast_set_flag(p, SIP_GOTREFER); + attempttransferres = attempt_transfer(p, p->refer_call); + if (attempttransferres == 0) { + if (p->refer_call->owner) + ast_mutex_unlock(&p->refer_call->owner->lock); + ast_mutex_unlock(&p->refer_call->lock); + p->refer_call = NULL; + ast_set_flag(p, SIP_GOTREFER); + } } else { ast_log(LOG_DEBUG,"202 Accepted (blind)\n"); c = p->owner; @@ -10802,12 +10805,16 @@ } ast_set_flag(p, SIP_GOTREFER); } - transmit_response(p, "202 Accepted", req); - transmit_notify_with_sipfrag(p, seqno); - /* Always increment on a BYE */ - if (!nobye) { - transmit_request_with_auth(p, SIP_BYE, 0, 1, 1); - ast_set_flag(p, SIP_ALREADYGONE); + if (attempttransferres == 0) { + transmit_response(p, "202 Accepted", req); + transmit_notify_with_sipfrag(p, seqno); + /* Always increment on a BYE */ + if (!nobye) { + transmit_request_with_auth(p, SIP_BYE, 0, 1, 1); + ast_set_flag(p, SIP_ALREADYGONE); + } + } else { + transmit_response(p, "603 Declined", req); } } }