res_pjsip_session: Add cleanup to ast_sip_session_terminate

If you use ast_request to create a PJSIP channel but then hang it
up without causing a transaction to be sent, the session will
never be destroyed.  This is due ot the fact that it's pjproject
that triggers the session cleanup when the transaction ends.
app_chanisavail was doing this to get more granular channel state
and it's also possible for this to happen via ARI.

* ast_sip_session_terminate was modified to explicitly call the
  cleanup tasks and unreference session if the invite state is NULL
  AND invite_tsx is NULL (meaning we never sent a transaction).

* chan_pjsip/hangup was modified to bump session before it calls
  ast_sip_session_terminate to insure that session stays valid
  while it does its own cleanup.

* Added test events to session_destructor for a future testsuite
  test.

ASTERISK-26908 #close
Reported-by: Richard Mudgett

Change-Id: I52daf6f757184e5544c261f64f6fe9602c4680a9
This commit is contained in:
George Joseph
2017-04-27 07:02:12 -06:00
parent d2bb9f21d4
commit c5b9ed20fd
3 changed files with 47 additions and 5 deletions

View File

@@ -457,6 +457,10 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
*
* \param session The session to terminate
* \param response The response code to use for termination if possible
*
* \warning Calling this function MAY cause the last session reference to be
* released and the session destructor to be called. If you need to do something
* with session after this call, be sure to bump the ref count before calling terminate.
*/
void ast_sip_session_terminate(struct ast_sip_session *session, int response);