--- ../pristine/asterisk-1.2.18/channels/chan_sip.c 2007-04-30 08:36:57.000000000 -0600 +++ channels/chan_sip.c 2007-04-30 08:54:33.000000000 -0600 @@ -2492,6 +2492,7 @@ if (!ast_test_flag(p, SIP_CAN_BYE)) { ast_set_flag(p, SIP_PENDINGBYE); /* Do we need a timer here if we don't hear from them at all? */ + sip_scheddestroy(p, 32000); } else { /* Send a new request: CANCEL */ transmit_request(p, SIP_CANCEL, p->ocseq, 1, 0); @@ -9743,15 +9744,14 @@ switch (resp) { case 100: /* Trying */ - if (!ignore) + if (!ignore && p->owner) sip_cancel_destroy(p); check_pendings(p); ast_set_flag(p, SIP_CAN_BYE); break; case 180: /* 180 Ringing */ - if (!ignore) - sip_cancel_destroy(p); if (!ignore && p->owner) { + sip_cancel_destroy(p); ast_queue_control(p->owner, AST_CONTROL_RINGING); if (p->owner->_state != AST_STATE_UP) ast_setstate(p->owner, AST_STATE_RINGING); @@ -9767,7 +9767,7 @@ check_pendings(p); break; case 183: /* Session progress */ - if (!ignore) + if (!ignore && p->owner) sip_cancel_destroy(p); /* Ignore 183 Session progress without SDP */ if (find_sdp(req)) { @@ -9781,7 +9781,7 @@ check_pendings(p); break; case 200: /* 200 OK on invite - someone's answering our call */ - if (!ignore) + if (!ignore && p->owner) sip_cancel_destroy(p); p->authtries = 0; if (find_sdp(req)) { @@ -9870,6 +9870,7 @@ ast_queue_hangup(p->owner); else if (!ignore) update_call_counter(p, DEC_CALL_LIMIT); + sip_scheddestroy(p, 32000); break; case 491: /* Pending */ /* we have to wait a while, then retransmit */ @@ -10261,7 +10262,7 @@ ast_set_flag(p, SIP_NEEDDESTROY); } else if ((resp >= 100) && (resp < 200)) { if (sipmethod == SIP_INVITE) { - if (!ignore) + if (!ignore && p->owner) sip_cancel_destroy(p); if (find_sdp(req)) process_sdp(p, req); @@ -10325,7 +10326,7 @@ break; default: /* Errors without handlers */ if ((resp >= 100) && (resp < 200)) { - if (sipmethod == SIP_INVITE && !ignore) /* re-invite */ + if (sipmethod == SIP_INVITE && !ignore && p->owner) /* re-invite */ sip_cancel_destroy(p); } @@ -10339,7 +10340,7 @@ case 503: /* Service Unavailable */ case 504: /* Server timeout */ - if (sipmethod == SIP_INVITE && !ignore) { /* re-invite failed */ + if (sipmethod == SIP_INVITE && !ignore && p->owner) { /* re-invite failed */ sip_cancel_destroy(p); } break; @@ -10617,7 +10618,8 @@ /* Use this as the basis */ if (debug) ast_verbose("Using INVITE request as basis request - %s\n", p->callid); - sip_cancel_destroy(p); + if(p->owner) + sip_cancel_destroy(p); /* This call is no longer outgoing if it ever was */ ast_clear_flag(p, SIP_OUTGOING); /* This also counts as a pending invite */