<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15123">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjsip: Match lifetime of INVITE session to our session.<br><br>In some circumstances it was possible for an INVITE<br>session to be destroyed while we were still using it.<br>This occurred due to the reference on the INVITE session<br>being released internally as a result of its state<br>changing to DISCONNECTED.<br><br>This change adds a reference to the INVITE session<br>which is released when our own session is destroyed,<br>ensuring that the INVITE session remains valid for<br>the lifetime of our session.<br><br>ASTERISK-29022<br><br>Change-Id: I300c6d9005ff0e6efbe1132daefc7e47ca6228c9<br>---<br>M channels/chan_pjsip.c<br>M res/res_pjsip_session.c<br>2 files changed, 30 insertions(+), 150 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/23/15123/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c</span><br><span>index 93889fc..b6944db 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -689,9 +689,6 @@</span><br><span> ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",</span><br><span> session->inv_session->cause,</span><br><span> pjsip_get_status_text(session->inv_session->cause)->ptr);</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> SCOPE_EXIT_RTN_VALUE(0, "Disconnected\n");</span><br><span> }</span><br><span> </span><br><span>@@ -708,10 +705,6 @@</span><br><span> ast_sip_session_send_response(session, packet);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> if (status != PJ_SUCCESS) {</span><br><span> char err[PJ_ERR_MSG_SIZE];</span><br><span> </span><br><span>@@ -744,14 +737,6 @@</span><br><span> ast_setstate(ast, AST_STATE_UP);</span><br><span> session = ao2_bump(channel->session);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_add_ref(session->inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Couldn't increase the session reference counter\n");</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(session, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- SCOPE_EXIT_RTN_VALUE(-1, "Couldn't increase the session reference counter\n");</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /* the answer task needs to be pushed synchronously otherwise a race condition</span><br><span> can occur between this thread and bridging (specifically when native bridging</span><br><span> attempts to do direct media) */</span><br><span>@@ -763,9 +748,6 @@</span><br><span> if (res == -1) {</span><br><span> ast_log(LOG_ERROR,"Cannot answer '%s': Unable to push answer task to the threadpool.\n",</span><br><span> ast_channel_name(session->channel));</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> }</span><br><span> ao2_ref(session, -1);</span><br><span> ast_channel_lock(ast);</span><br><span>@@ -1358,9 +1340,6 @@</span><br><span> ast_sip_session_send_response(session, packet);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> ao2_ref(ind_data, -1);</span><br><span> </span><br><span> return 0;</span><br><span>@@ -1392,31 +1371,20 @@</span><br><span> ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",</span><br><span> session->inv_session->cause,</span><br><span> pjsip_get_status_text(session->inv_session->cause)->ptr);</span><br><span style="color: hsl(0, 100%, 40%);">- goto failure;</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> }</span><br><span> </span><br><span> if (ast_sip_create_request("INFO", session->inv_session->dlg, session->endpoint, NULL, NULL, &tdata)) {</span><br><span> ast_log(LOG_ERROR, "Could not create text video update INFO request\n");</span><br><span style="color: hsl(0, 100%, 40%);">- goto failure;</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> }</span><br><span> if (ast_sip_add_body(tdata, &body)) {</span><br><span> ast_log(LOG_ERROR, "Could not add body to text video update INFO request\n");</span><br><span style="color: hsl(0, 100%, 40%);">- goto failure;</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> }</span><br><span> ast_sip_session_send_request(session, tdata);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-failure:</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span>@@ -1464,9 +1432,6 @@</span><br><span> ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",</span><br><span> session->inv_session->cause,</span><br><span> pjsip_get_status_text(session->inv_session->cause)->ptr);</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> ao2_ref(session, -1);</span><br><span> return -1;</span><br><span> }</span><br><span>@@ -1507,10 +1472,6 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> ao2_ref(session, -1);</span><br><span> return 0;</span><br><span> }</span><br><span>@@ -1742,18 +1703,9 @@</span><br><span> res = ast_rtp_instance_write(media->rtp, &fr);</span><br><span> } else {</span><br><span> ao2_ref(channel->session, +1);</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_add_ref(channel->session->inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Can't increase the session reference counter\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_push_task(channel->session->serializer, transmit_info_with_vidupdate, channel->session)) {</span><br><span> ao2_cleanup(channel->session);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_sip_push_task(channel->session->serializer, transmit_info_with_vidupdate, channel->session)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_cleanup(channel->session);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> }</span><br><span> ast_test_suite_event_notify("AST_CONTROL_VIDUPDATE", "Result: Success");</span><br><span> } else {</span><br><span>@@ -1767,17 +1719,7 @@</span><br><span> break;</span><br><span> case AST_CONTROL_CONNECTED_LINE:</span><br><span> ao2_ref(channel->session, +1);</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_add_ref(channel->session->inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_cleanup(channel->session);</span><br><span style="color: hsl(0, 100%, 40%);">- SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Couldn't increase the session reference counter\n",</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_name(ast));</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> if (ast_sip_push_task(channel->session->serializer, update_connected_line_information, channel->session)) {</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(channel->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> ao2_cleanup(channel->session);</span><br><span> }</span><br><span> break;</span><br><span>@@ -1884,18 +1826,10 @@</span><br><span> if (!ind_data) {</span><br><span> SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Couldn't alloc indicate data\n", ast_channel_name(ast));</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_add_ref(ind_data->session->inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_cleanup(ind_data);</span><br><span style="color: hsl(0, 100%, 40%);">- SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Couldn't increase the session reference counter\n", ast_channel_name(ast));</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (ast_sip_push_task(channel->session->serializer, indicate, ind_data)) {</span><br><span> ast_log(LOG_ERROR, "%s: Cannot send response code %d to endpoint %s. Could not queue task properly\n",</span><br><span> ast_channel_name(ast), response_code, ast_sorcery_object_get_id(channel->session->endpoint));</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(ind_data->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> ao2_cleanup(ind_data);</span><br><span> res = -1;</span><br><span> }</span><br><span>@@ -2166,10 +2100,6 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(trnf_data->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> ao2_ref(trnf_data, -1);</span><br><span> ao2_cleanup(endpoint);</span><br><span> ao2_cleanup(contact);</span><br><span>@@ -2186,19 +2116,8 @@</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_add_ref(trnf_data->session->inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Can't increase the session reference counter\n");</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_cleanup(trnf_data);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> if (ast_sip_push_task(channel->session->serializer, transfer, trnf_data)) {</span><br><span> ast_log(LOG_WARNING, "Error requesting transfer\n");</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(trnf_data->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> ao2_cleanup(trnf_data);</span><br><span> return -1;</span><br><span> }</span><br><span>@@ -2293,12 +2212,12 @@</span><br><span> ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",</span><br><span> session->inv_session->cause,</span><br><span> pjsip_get_status_text(session->inv_session->cause)->ptr);</span><br><span style="color: hsl(0, 100%, 40%);">- goto failure;</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> }</span><br><span> </span><br><span> if (!(body_text = ast_str_create(32))) {</span><br><span> ast_log(LOG_ERROR, "Could not allocate buffer for INFO DTMF.\n");</span><br><span style="color: hsl(0, 100%, 40%);">- goto failure;</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> }</span><br><span> ast_str_set(&body_text, 0, "Signal=%c\r\nDuration=%u\r\n", dtmf_data->digit, dtmf_data->duration);</span><br><span> </span><br><span>@@ -2306,27 +2225,16 @@</span><br><span> </span><br><span> if (ast_sip_create_request("INFO", session->inv_session->dlg, session->endpoint, NULL, NULL, &tdata)) {</span><br><span> ast_log(LOG_ERROR, "Could not create DTMF INFO request\n");</span><br><span style="color: hsl(0, 100%, 40%);">- goto failure;</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> }</span><br><span> if (ast_sip_add_body(tdata, &body)) {</span><br><span> ast_log(LOG_ERROR, "Could not add body to DTMF INFO request\n");</span><br><span> pjsip_tx_data_dec_ref(tdata);</span><br><span style="color: hsl(0, 100%, 40%);">- goto failure;</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> }</span><br><span> ast_sip_session_send_request(session, tdata);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-failure:</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> }</span><br><span> </span><br><span> /*! \brief Function called by core to stop a DTMF digit */</span><br><span>@@ -2367,19 +2275,8 @@</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_add_ref(dtmf_data->session->inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Can't increase the session reference counter\n");</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_cleanup(dtmf_data);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> if (ast_sip_push_task(channel->session->serializer, transmit_info_dtmf, dtmf_data)) {</span><br><span> ast_log(LOG_WARNING, "Error sending DTMF via INFO.\n");</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(dtmf_data->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> ao2_cleanup(dtmf_data);</span><br><span> return -1;</span><br><span> }</span><br><span>@@ -2888,10 +2785,6 @@</span><br><span> ast_sip_send_request(tdata, data->session->inv_session->dlg, data->session->endpoint, NULL, NULL);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(data->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> ao2_cleanup(data);</span><br><span> </span><br><span> return 0;</span><br><span>@@ -2913,18 +2806,7 @@</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_add_ref(data->session->inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Can't increase the session reference counter\n");</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(data, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> if (ast_sip_push_task(channel->session->serializer, sendtext, data)) {</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(data->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> ao2_ref(data, -1);</span><br><span> return -1;</span><br><span> }</span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index ec01145..e07b18e 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -2999,6 +2999,9 @@</span><br><span> </span><br><span> if (session->inv_session) {</span><br><span> pjsip_dlg_dec_session(session->inv_session->dlg, &session_module);</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_inv_dec_ref(session->inv_session);</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span> }</span><br><span> </span><br><span> ast_test_suite_event_notify("SESSION_DESTROYED", "Endpoint: %s", endpoint_name);</span><br><span>@@ -3106,6 +3109,24 @@</span><br><span> }</span><br><span> ast_sip_dialog_set_serializer(inv_session->dlg, session->serializer);</span><br><span> ast_sip_dialog_set_endpoint(inv_session->dlg, endpoint);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* When a PJSIP INVITE session is created it is created with a reference</span><br><span style="color: hsl(120, 100%, 40%);">+ * count of 1, with that reference being managed by the underlying state</span><br><span style="color: hsl(120, 100%, 40%);">+ * of the INVITE session itself. When the INVITE session transitions to</span><br><span style="color: hsl(120, 100%, 40%);">+ * a DISCONNECTED state that reference is released. This means we can not</span><br><span style="color: hsl(120, 100%, 40%);">+ * rely on that reference to ensure the INVITE session remains for the</span><br><span style="color: hsl(120, 100%, 40%);">+ * lifetime of our session. To ensure it does we add our own reference</span><br><span style="color: hsl(120, 100%, 40%);">+ * and release it when our own session goes away, ensuring that the INVITE</span><br><span style="color: hsl(120, 100%, 40%);">+ * session remains for the lifetime of session.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pjsip_inv_add_ref(inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Can't increase the session reference counter\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> pjsip_dlg_inc_session(inv_session->dlg, &session_module);</span><br><span> inv_session->mod_data[session_module.id] = ao2_bump(session);</span><br><span> session->contact = ao2_bump(contact);</span><br><span>@@ -3868,9 +3889,6 @@</span><br><span> ast_sip_session_get_name(invite->session),</span><br><span> invite->session->inv_session->cause,</span><br><span> pjsip_get_status_text(invite->session->inv_session->cause)->ptr);</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(invite->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> SCOPE_EXIT_RTN_VALUE(-1);</span><br><span> }</span><br><span> </span><br><span>@@ -3988,9 +4006,6 @@</span><br><span> handle_incoming_request(invite->session, invite->rdata);</span><br><span> </span><br><span> end:</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(invite->session->inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> SCOPE_EXIT_RTN_VALUE(0, "%s\n", ast_sip_session_get_name(invite->session));</span><br><span> }</span><br><span> </span><br><span>@@ -4014,20 +4029,6 @@</span><br><span> SCOPE_EXIT_RTN("Failure in pre session setup\n");</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_add_ref(inv_session) != PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Can't increase the session reference counter\n");</span><br><span style="color: hsl(0, 100%, 40%);">- if (inv_session->state != PJSIP_INV_STATE_DISCONNECTED) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_terminate(inv_session, 500, PJ_FALSE);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_send_msg(inv_session, tdata);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- SCOPE_EXIT_RTN("Couldn't add invite session reference\n");</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> session = ast_sip_session_alloc(endpoint, NULL, inv_session, rdata);</span><br><span> if (!session) {</span><br><span> if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {</span><br><span>@@ -4035,9 +4036,6 @@</span><br><span> } else {</span><br><span> pjsip_inv_send_msg(inv_session, tdata);</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef HAVE_PJSIP_INV_SESSION_REF</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_inv_dec_ref(inv_session);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> SCOPE_EXIT_RTN("Couldn't create session\n");</span><br><span> }</span><br><span> session->call_direction = AST_SIP_SESSION_INCOMING_CALL;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15123">change 15123</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15123"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I300c6d9005ff0e6efbe1132daefc7e47ca6228c9 </div>
<div style="display:none"> Gerrit-Change-Number: 15123 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>