<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8661">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip:  Correct usages of pjproject's timer heap<br><br>Fix some timer heap initializations and cancels to try and prevent<br>crashes and timer heap issues.<br><br>Change-Id: I64885d190fa22097d1b55987091375541e57a7ee<br>---<br>M res/res_pjsip_outbound_publish.c<br>M res/res_pjsip_outbound_registration.c<br>M res/res_pjsip_session.c<br>M res/res_pjsip_t38.c<br>4 files changed, 13 insertions(+), 14 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/8661/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip_outbound_publish.c b/res/res_pjsip_outbound_publish.c<br>index 6b40ff4..b170232 100644<br>--- a/res/res_pjsip_outbound_publish.c<br>+++ b/res/res_pjsip_outbound_publish.c<br>@@ -291,7 +291,8 @@<br> /*! \brief Helper function which cancels the refresh timer on a client */<br> static void cancel_publish_refresh(struct ast_sip_outbound_publish_client *client)<br> {<br>-   if (pj_timer_heap_cancel(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()), &client->timer)) {<br>+ if (pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),<br>+         &client->timer, 0)) {<br>          /* The timer was successfully cancelled, drop the refcount of the client */<br>           ao2_ref(client, -1);<br>  }<br>@@ -1090,8 +1091,7 @@<br>              return NULL;<br>  }<br> <br>- state->client->timer.user_data = state->client;<br>-     state->client->timer.cb = sip_outbound_publish_timer_cb;<br>+       pj_timer_entry_init(&state->client->timer, 0, state->client, sip_outbound_publish_timer_cb);<br>     state->client->transport_name = ast_strdup(publish->transport);<br>      state->client->publish = ao2_bump(publish);<br> <br>diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c<br>index e3799fb..e4faef5 100644<br>--- a/res/res_pjsip_outbound_registration.c<br>+++ b/res/res_pjsip_outbound_registration.c<br>@@ -512,7 +512,8 @@<br> /*! \brief Helper function which cancels the timer on a client */<br> static void cancel_registration(struct sip_outbound_registration_client_state *client_state)<br> {<br>-        if (pj_timer_heap_cancel(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()), &client_state->timer)) {<br>+   if (pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),<br>+         &client_state->timer, client_state->timer.id)) {<br>            /* The timer was successfully cancelled, drop the refcount of client_state */<br>                 ao2_ref(client_state, -1);<br>    }<br>@@ -1130,8 +1131,8 @@<br>      }<br> <br>  state->client_state->status = SIP_REGISTRATION_UNREGISTERED;<br>-   state->client_state->timer.user_data = state->client_state;<br>- state->client_state->timer.cb = sip_outbound_registration_timer_cb;<br>+    pj_timer_entry_init(&state->client_state->timer, 0, state->client_state,<br>+                sip_outbound_registration_timer_cb);<br>  state->client_state->transport_name = ast_strdup(registration->transport);<br>   state->client_state->registration_name =<br>                ast_strdup(ast_sorcery_object_get_id(registration));<br>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c<br>index d74796e..982fd28 100644<br>--- a/res/res_pjsip_session.c<br>+++ b/res/res_pjsip_session.c<br>@@ -1883,10 +1883,8 @@<br>     session->defer_end = 1;<br>    session->ended_while_deferred = 0;<br> <br>-     session->scheduled_termination.id = 0;<br>     ao2_ref(session, +1);<br>-        session->scheduled_termination.user_data = session;<br>-       session->scheduled_termination.cb = session_termination_cb;<br>+       pj_timer_entry_init(&session->scheduled_termination, 0, session, session_termination_cb);<br> <br>   res = (pjsip_endpt_schedule_timer(ast_sip_get_pjsip_endpoint(),<br>               &session->scheduled_termination, &delay) != PJ_SUCCESS) ? -1 : 0;<br>@@ -1908,8 +1906,8 @@<br>  */<br> static void sip_session_defer_termination_stop_timer(struct ast_sip_session *session)<br> {<br>-        if (pj_timer_heap_cancel(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),<br>-           &session->scheduled_termination)) {<br>+   if (pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),<br>+         &session->scheduled_termination, session->scheduled_termination.id)) {<br>              ao2_ref(session, -1);<br>         }<br> }<br>diff --git a/res/res_pjsip_t38.c b/res/res_pjsip_t38.c<br>index 5f04f0e..a3cdc57 100644<br>--- a/res/res_pjsip_t38.c<br>+++ b/res/res_pjsip_t38.c<br>@@ -137,7 +137,8 @@<br>               new_state, old_state,<br>                 session->channel ? ast_channel_name(session->channel) : "<gone>");<br> <br>-  if (pj_timer_heap_cancel(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()), &state->timer)) {<br>+  if (pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),<br>+         &state->timer, 0)) {<br>           ast_debug(2, "Automatic T.38 rejection on channel '%s' terminated\n",<br>                       session->channel ? ast_channel_name(session->channel) : "<gone>");<br>              ao2_ref(session, -1);<br>@@ -242,8 +243,7 @@<br>    state = datastore->data;<br> <br>        /* This will get bumped up before scheduling */<br>-      state->timer.user_data = session;<br>- state->timer.cb = t38_automatic_reject_timer_cb;<br>+  pj_timer_entry_init(&state->timer, 0, session, t38_automatic_reject_timer_cb);<br> <br>      datastore->data = state;<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8661">change 8661</a>. To unsubscribe, 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/8661"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I64885d190fa22097d1b55987091375541e57a7ee </div>
<div style="display:none"> Gerrit-Change-Number: 8661 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>