--- 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-18 08:46:06.000000000 +0200 @@ -12164,8 +12164,22 @@ } /* Save Record-Route for any later requests we make on this dialogue */ - if (!reinvite) - build_route(p, req, 1); + if (!reinvite) { + /* When doing reinvites, after a hangeup, we get the following + exchange: + INVITE ----> + <-------- OK + ACK -------> + However, after the INVITE, sip_hangup() is called, which sets + owner to NULL, causing the test above to think we are not in + a reinvite. To ensure the ack is sent correctly, we have to + catch this situation here. */ + if (! p->owner && p->invitestate == INV_CONFIRMED) + if (sipdebug) + ast_log(LOG_DEBUG, "Assuming this is a reinvite for a call we're hanging up.\n"); + else + build_route(p, req, 1); + } } if (p->owner && (p->owner->_state == AST_STATE_UP) && (bridgepeer = ast_bridged_channel(p->owner))) { /* if this is a re-invite */