<blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><p style="white-space: pre-wrap; word-wrap: break-word;">Patch Set 2:</p><p style="white-space: pre-wrap; word-wrap: break-word;">You are not carefully reading the clarification of the changes I have made. Please read the above explanations again.</p><p style="white-space: pre-wrap; word-wrap: break-word;">Note that I did not come up with this approach to managing objects, I only adhere to this rule.</p><p style="white-space: pre-wrap; word-wrap: break-word;">The subscription logic allows you to subscribe not only to one but also to several applications to the same subscription. The only difference is that there are two ways to store objects for later search and retrieval:<br>1. Vector for technology subscriptions (tech_subscriptions)<br>2. Special container for resource subscriptions (endpoint_subscriptions)</p></blockquote><p style="white-space: pre-wrap; word-wrap: break-word;">Normally yes you would want applications to also have a reference to the subscription so subscription can automatically be destroyed, but in this implementation applications do not actually have a reference to the subscription so it doesn't actually help and doesn't provide automatic lifetime tracking. Subscription lifetime still has to be manually managed through the subscription subscribe/unsubscribe implementation because the subscription is stored within tech_subscriptions or endpoint_subscriptions.</p><p style="white-space: pre-wrap; word-wrap: break-word;">This is why the intended reference counting model does not do reference counting on the subscription based on the applications. The intention appears to have been "as long as there is one application then the subscription has a minimum reference count of 1".</p><p style="white-space: pre-wrap; word-wrap: break-word;">Your change alters the reference counting model to make it follow the number of applications, but I'm not sure that's necessary based on my past comment regarding moving "ao2_ref(sub, -1);" to be in the tech_subscriptions block.</p><p style="white-space: pre-wrap; word-wrap: break-word;">With that change:</p><p style="white-space: pre-wrap; word-wrap: break-word;">In messaging_app_subscribe_endpoint get_or_create_subscription will get or create a subscription and store it in either endpoint_subscriptions or tech_subscriptions - this function will then return and in total there are 2 references at that point. The messaging_app_subscribe_endpoint function releases the reference passed to it from get_or_create_subscription at the end because of RAII_VAR - leaving the reference count at 1.</p><p style="white-space: pre-wrap; word-wrap: break-word;">In messaging_app_unsubscribe_endpoint if the "ao2_ref(sub, -1);" is moved then only the case where there are no more applications will the reference held by endpoint_subscriptions or tech_subscriptions be released. This is because in the case where there are applications remaining the reference returned by get_subscription is balanced by the RAII_VAR in messaging_app_unsubscribe_endpoint, and the reference held by endpoint_subscriptions or tech_subscriptions is untouched.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15762">View Change</a></p><ul style="list-style: none; padding: 0;"></ul><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: 2 </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: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Comment-Date: Mon, 24 May 2021 13:20:00 +0000 </div>
<div style="display:none"> Gerrit-HasComments: No </div>
<div style="display:none"> Gerrit-Has-Labels: No </div>
<div style="display:none"> Gerrit-MessageType: comment </div>