<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10209">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stasis: Add function to delete topic from pool<br><br>There's been a long standing leak when using topic pools. The<br>topics in the pool get cleaned up when the last pool reference is<br>released but you can't remove a topic specifically. If you reloaded<br>app_voicemail for instance, and mailboxes went away, their topics<br>were left in the pool.<br><br>* Added stasis_topic_pool_delete_topic() so modules can clean up<br> topics from pools.<br>* Registered the topic pool containers so it can be examined from<br> the CLI when AO2_DEBUG is enabled. They'll be named<br> "<topic_pool_name>-pool".<br><br>Change-Id: Ib7957951ee5c9b9b4482af7b9b4349112d62bc25<br>---<br>M include/asterisk/stasis.h<br>M main/stasis.c<br>2 files changed, 48 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/09/10209/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/stasis.h b/include/asterisk/stasis.h</span><br><span>index bca6d40..8329dd0 100644</span><br><span>--- a/include/asterisk/stasis.h</span><br><span>+++ b/include/asterisk/stasis.h</span><br><span>@@ -753,6 +753,18 @@</span><br><span> struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Delete a topic from the topic pool</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param pool Pool from which to delete the topic</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param topic_name Name of the topic to delete</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.24</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 15.6</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 16.1</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void stasis_topic_pool_delete_topic(struct stasis_topic_pool *pool, const char *topic_name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Check if a topic exists in a pool</span><br><span> * \param pool Pool to check</span><br><span> * \param topic_name Name of the topic to check</span><br><span>diff --git a/main/stasis.c b/main/stasis.c</span><br><span>index 1616deb..c20156f 100644</span><br><span>--- a/main/stasis.c</span><br><span>+++ b/main/stasis.c</span><br><span>@@ -1079,6 +1079,15 @@</span><br><span> {</span><br><span> struct stasis_topic_pool *pool = obj;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AO2_DEBUG</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *container_name =</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_alloca(strlen(stasis_topic_name(pool->pool_topic)) + strlen("-pool") + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ sprintf(container_name, "%s-pool", stasis_topic_name(pool->pool_topic));</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_container_unregister(container_name);</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> ao2_cleanup(pool->pool_container);</span><br><span> pool->pool_container = NULL;</span><br><span> ao2_cleanup(pool->pool_topic);</span><br><span>@@ -1143,6 +1152,18 @@</span><br><span> return CMP_MATCH;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AO2_DEBUG</span><br><span style="color: hsl(120, 100%, 40%);">+static void topic_pool_prnt_obj(void *v_obj, void *where, ao2_prnt_fn *prnt)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct topic_pool_entry *entry = v_obj;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!entry) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ prnt(where, "%s", stasis_topic_name(entry->topic));</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> struct stasis_topic_pool *stasis_topic_pool_create(struct stasis_topic *pooled_topic)</span><br><span> {</span><br><span> struct stasis_topic_pool *pool;</span><br><span>@@ -1158,12 +1179,27 @@</span><br><span> ao2_cleanup(pool);</span><br><span> return NULL;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AO2_DEBUG</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *container_name =</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_alloca(strlen(stasis_topic_name(pooled_topic)) + strlen("-pool") + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ sprintf(container_name, "%s-pool", stasis_topic_name(pooled_topic));</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_container_register(container_name, pool->pool_container, topic_pool_prnt_obj);</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> ao2_ref(pooled_topic, +1);</span><br><span> pool->pool_topic = pooled_topic;</span><br><span> </span><br><span> return pool;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void stasis_topic_pool_delete_topic(struct stasis_topic_pool *pool, const char *topic_name)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_find(pool->pool_container, topic_name, OBJ_SEARCH_KEY | OBJ_NODATA | OBJ_UNLINK);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name)</span><br><span> {</span><br><span> RAII_VAR(struct topic_pool_entry *, topic_pool_entry, NULL, ao2_cleanup);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10209">change 10209</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/10209"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ib7957951ee5c9b9b4482af7b9b4349112d62bc25 </div>
<div style="display:none"> Gerrit-Change-Number: 10209 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>