<p>Evgenios Muratidis has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15762">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Core/Stasis: Fix "FRACK!, Failed assertion bad magic number" happens when unsubscribe an application from an event source<br><br>Several changes have been made to fix bugs related to applications subscriptions either by technology or by specific resources of the Endpoint's subscriptions<br><br>* Fixed a typo in get_subscription when calling ao2_find (needs to pass the Endpoint's Id and not the whole object)<br>* Fixed return a wrong subscription's object in get_subscription when check fails at search by Endpoint's technology block of code<br>* In messaging_app_subscribe_endpoint added lines to up the subscription's reference counter in case more than 1 application is subscribed to<br>* In messaging_app_unsubscribe_endpoint added line to up the subscription's reference counter, at search by Endpoint's resource block of code, cause the below ao2_unlink decreases the subscription's reference counter by 1 and cause follow lines of code decreases it 2 times more, one by calling ao2_ref, and one by auto-calling ao2_cleanup for the subscription's object when the function goes out of scope (through RAII_VAR macro)<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, 13 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/62/15762/1</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 a7716b8..decd230 100644</span><br><span>--- a/res/stasis/messaging.c</span><br><span>+++ b/res/stasis/messaging.c</span><br><span>@@ -385,7 +385,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>@@ -397,6 +397,9 @@</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 wrong using since the above check fails */</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>@@ -425,6 +428,10 @@</span><br><span>     if (AST_VECTOR_SIZE(&sub->applications) == 0) {</span><br><span>               if (endpoint && !ast_strlen_zero(ast_endpoint_get_resource(endpoint))) {</span><br><span>                     ao2_unlink(endpoint_subscriptions, sub);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                    /* Need to up the subscription's reference counter again, cause of the above call decreases it by 1</span><br><span style="color: hsl(120, 100%, 40%);">+                          and cause it will be decreased 2 times at follow lines of code */</span><br><span style="color: hsl(120, 100%, 40%);">+                  ao2_bump(sub);</span><br><span>               } else {</span><br><span>                     ast_rwlock_wrlock(&tech_subscriptions_lock);</span><br><span>                     AST_VECTOR_REMOVE_CMP_UNORDERED(&tech_subscriptions, endpoint ? ast_endpoint_get_id(endpoint) : TECH_WILDCARD,</span><br><span>@@ -495,6 +502,11 @@</span><br><span>            ao2_unlock(sub);</span><br><span>             return -1;</span><br><span>   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Need up the subscription's reference counter since the subscription has more than 1 application subscribed to */</span><br><span style="color: hsl(120, 100%, 40%);">+       if (AST_VECTOR_SIZE(&sub->applications) > 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+              ao2_bump(sub);</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span>    ao2_unlock(sub);</span><br><span> </span><br><span>         ast_debug(3, "App '%s' subscribed to messages from endpoint '%s'\n", app_name, endpoint ? ast_endpoint_get_id(endpoint) : "-- ALL --");</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.5 </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: 1 </div>
<div style="display:none"> Gerrit-Owner: Evgenios Muratidis <jone1984@hotmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>