Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 376570) +++ channels/chan_sip.c (working copy) @@ -25820,6 +25820,24 @@ if (!ast_strlen_zero(referred_by)) { pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER_REFERER", referred_by); } + + /* When a call is transferred to voicemail from a Digium phone, there may be + * a Diversion header present in the REFER with an appropriate reason parameter + * set. We need to update the redirecting information appropriately. + */ + ast_channel_lock(p->owner); + sip_pvt_lock(p); + ast_party_redirecting_init(&redirecting); + memset(&update_redirecting, 0, sizeof(update_redirecting)); + change_redirecting_information(p, req, &redirecting, &update_redirecting, FALSE); + + /* Do not hold the pvt lock during a call that causes an indicate or an async_goto. + * Those functions lock channels which will invalidate locking order if the pvt lock + * is held.*/ + sip_pvt_unlock(p); + ast_channel_unlock(p->owner); + ast_channel_update_redirecting(current.chan2, &redirecting, &update_redirecting); + ast_party_redirecting_free(&redirecting); } sip_pvt_lock(p); @@ -25867,21 +25885,6 @@ } ast_set_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ - /* When a call is transferred to voicemail from a Digium phone, there may be - * a Diversion header present in the REFER with an appropriate reason parameter - * set. We need to update the redirecting information appropriately. - */ - ast_party_redirecting_init(&redirecting); - memset(&update_redirecting, 0, sizeof(update_redirecting)); - change_redirecting_information(p, req, &redirecting, &update_redirecting, FALSE); - - /* Do not hold the pvt lock during a call that causes an indicate or an async_goto. - * Those functions lock channels which will invalidate locking order if the pvt lock - * is held.*/ - sip_pvt_unlock(p); - ast_channel_update_redirecting(current.chan2, &redirecting, &update_redirecting); - ast_party_redirecting_free(&redirecting); - /* For blind transfers, move the call to the new extensions. For attended transfers on multiple * servers - generate an INVITE with Replaces. Either way, let the dial plan decided * indicate before masquerade so the indication actually makes it to the real channel