diff -ruN asterisk-1.4.19_orig/channels/chan_sip.c asterisk-1.4.19/channels/chan_sip.c --- asterisk-1.4.19_orig/channels/chan_sip.c 2008-03-26 20:04:35.000000000 +0100 +++ asterisk-1.4.19/channels/chan_sip.c 2008-04-29 16:58:31.000000000 +0200 @@ -734,6 +734,7 @@ #define SIP_DTMF_INBAND (1 << 16) /*!< DTMF Support: Inband audio, only for ULAW/ALAW - "inband" */ #define SIP_DTMF_INFO (2 << 16) /*!< DTMF Support: SIP Info messages - "info" */ #define SIP_DTMF_AUTO (3 << 16) /*!< DTMF Support: AUTO switch between rfc2833 and in-band DTMF */ +#define SIP_REINVITE_BYE (1 << 17) /*!< This call is a reinvite being hung up */ /* NAT settings */ #define SIP_NAT (3 << 18) /*!< four settings, uses two bits */ #define SIP_NAT_NEVER (0 << 18) /*!< No nat support */ @@ -3491,6 +3492,9 @@ ast_log(LOG_DEBUG, "Asked to hangup channel that was not connected\n"); return 0; } + /* Check for reinvite like we do in handle_response_invite(), although + oej said this was not correct. */ + int reinvite = (p->owner && p->owner->_state == AST_STATE_UP); if (ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) { if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { @@ -3550,6 +3554,11 @@ p->owner = NULL; ast->tech_pvt = NULL; + /* We need to make sure handle_response_invite() knows this is a + reinvite, so set the flag. Ideally this should be set at the + first possible instance we know this is a reinvite. */ + if (reinvite) + ast_set_flag(&p->flags[0], SIP_REINVITE_BYE); ast_module_unref(ast_module_info->self); @@ -12052,7 +12061,7 @@ int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING); int res = 0; int xmitres = 0; - int reinvite = (p->owner && p->owner->_state == AST_STATE_UP); + int reinvite = ((p->owner && p->owner->_state == AST_STATE_UP) || ast_test_flag(&p->flags[0], SIP_REINVITE_BYE)); struct ast_channel *bridgepeer = NULL; if (option_debug > 3) {