<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15762">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stasis: Fix "FRACK!, Failed assertion bad magic number" when unsubscribing<br><br>When unsubscribing from an endpoint technology a FRACK<br>would occur due to incorrect reference counting. This fixes<br>that issue, along with some other issues.<br><br>Fixed a typo in get_subscription when calling ao2_find as it<br>needed to pass the endpoint ID and not the entire object.<br><br>Fixed scenario where a subscription would get returned when<br>it shouldn't have been when searching based on endpoint<br>technology.<br><br>A doulbe unreference has also been resolved by only explicitly<br>releasing the reference held by tech_subscriptions.<br><br>ASTERISK-28237 #close<br>Reported by: Lucas Tardioli Silveira<br><br>Change-Id: Ia91b15f8e5ea68f850c66889a6325d9575901729<br>---<br>M res/stasis/messaging.c<br>1 file changed, 12 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/stasis/messaging.c b/res/stasis/messaging.c</span><br><span>index 2caa8ed..e1d54c4 100644</span><br><span>--- a/res/stasis/messaging.c</span><br><span>+++ b/res/stasis/messaging.c</span><br><span>@@ -396,7 +396,7 @@</span><br><span>        struct message_subscription *sub = NULL;</span><br><span> </span><br><span>         if (endpoint && !ast_strlen_zero(ast_endpoint_get_resource(endpoint))) {</span><br><span style="color: hsl(0, 100%, 40%);">-                sub = ao2_find(endpoint_subscriptions, endpoint, OBJ_SEARCH_KEY);</span><br><span style="color: hsl(120, 100%, 40%);">+             sub = ao2_find(endpoint_subscriptions, ast_endpoint_get_id(endpoint), OBJ_SEARCH_KEY);</span><br><span>       } else {</span><br><span>             int i;</span><br><span> </span><br><span>@@ -408,6 +408,11 @@</span><br><span>                            ao2_bump(sub);</span><br><span>                               break;</span><br><span>                       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                   /* Need to reset the pointer at this line to prevent from using the wrong subscription due to</span><br><span style="color: hsl(120, 100%, 40%);">+                  * the token check failing.</span><br><span style="color: hsl(120, 100%, 40%);">+                    */</span><br><span style="color: hsl(120, 100%, 40%);">+                   sub = NULL;</span><br><span>          }</span><br><span>            ast_rwlock_unlock(&tech_subscriptions_lock);</span><br><span>     }</span><br><span>@@ -441,10 +446,10 @@</span><br><span>                    AST_VECTOR_REMOVE_CMP_UNORDERED(&tech_subscriptions, endpoint ? ast_endpoint_get_id(endpoint) : TECH_WILDCARD,</span><br><span>                           messaging_subscription_cmp, AST_VECTOR_ELEM_CLEANUP_NOOP);</span><br><span>                   ast_rwlock_unlock(&tech_subscriptions_lock);</span><br><span style="color: hsl(120, 100%, 40%);">+                      ao2_ref(sub, -1); /* Release the reference held by tech_subscriptions */</span><br><span>             }</span><br><span>    }</span><br><span>    ao2_unlock(sub);</span><br><span style="color: hsl(0, 100%, 40%);">-        ao2_ref(sub, -1);</span><br><span> </span><br><span>        ast_debug(3, "App '%s' unsubscribed to messages from endpoint '%s'\n", app_name, endpoint ? ast_endpoint_get_id(endpoint) : "-- ALL --");</span><br><span>        ast_test_suite_event_notify("StasisMessagingSubscription", "SubState: Unsubscribed\r\nAppName: %s\r\nToken: %s\r\n",</span><br><span>@@ -464,6 +469,11 @@</span><br><span>              return NULL;</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Either endpoint_subscriptions or tech_subscriptions will hold a reference to</span><br><span style="color: hsl(120, 100%, 40%);">+        * the subscription. This reference is released to allow the subscription to</span><br><span style="color: hsl(120, 100%, 40%);">+   * eventually destruct when there are no longer any applications receiving</span><br><span style="color: hsl(120, 100%, 40%);">+     * events from the subscription.</span><br><span style="color: hsl(120, 100%, 40%);">+       */</span><br><span>  if (endpoint && !ast_strlen_zero(ast_endpoint_get_resource(endpoint))) {</span><br><span>             ao2_link(endpoint_subscriptions, sub);</span><br><span>       } else {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15762">change 15762</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/+/15762"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Ia91b15f8e5ea68f850c66889a6325d9575901729 </div>
<div style="display:none"> Gerrit-Change-Number: 15762 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Evgenios Muratidis <jone1984@hotmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>