[asterisk-commits] dlee: branch dlee/stasis-core r382477 - in /team/dlee/stasis-core: include/as...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 5 16:35:57 CST 2013


Author: dlee
Date: Tue Mar  5 16:35:53 2013
New Revision: 382477

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382477
Log:
Address leakage of caching_topic subscriptions.

There's still a leak in the cache, but hopefully I'll clear that up after
bringing in kmoore's subscribe/unsubscribe notification patch.

Modified:
    team/dlee/stasis-core/include/asterisk/stasis.h
    team/dlee/stasis-core/main/stasis_cache.c
    team/dlee/stasis-core/tests/test_stasis.c

Modified: team/dlee/stasis-core/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/include/asterisk/stasis.h?view=diff&rev=382477&r1=382476&r2=382477
==============================================================================
--- team/dlee/stasis-core/include/asterisk/stasis.h (original)
+++ team/dlee/stasis-core/include/asterisk/stasis.h Tue Mar  5 16:35:53 2013
@@ -397,6 +397,13 @@
 struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *original_topic, snapshot_get_id id_fn);
 
 /*!
+ * Unsubscribes a caching topic from its upstream topic.
+ * \param caching_topic Caching topic to unsubscribe
+ * \since 12
+ */
+void stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic);
+
+/*!
  * \brief Returns the topic of cached events from a caching topics.
  * \param caching_topic The caching topic.
  * \return The topic that publishes cache update events, along with passthrough events

Modified: team/dlee/stasis-core/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/stasis_cache.c?view=diff&rev=382477&r1=382476&r2=382477
==============================================================================
--- team/dlee/stasis-core/main/stasis_cache.c (original)
+++ team/dlee/stasis-core/main/stasis_cache.c Tue Mar  5 16:35:53 2013
@@ -45,6 +45,7 @@
 struct stasis_caching_topic {
 	struct ao2_container *cache;
 	struct stasis_topic *topic;
+	struct stasis_subscription *sub;
 	snapshot_get_id id_fn;
 };
 
@@ -59,6 +60,19 @@
 struct stasis_topic *stasis_caching_get_topic(struct stasis_caching_topic *caching_topic)
 {
 	return caching_topic->topic;
+}
+
+void stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
+{
+	if (caching_topic) {
+		if (caching_topic->sub) {
+			stasis_unsubscribe(caching_topic->sub);
+			caching_topic->sub = NULL;
+			ao2_cleanup(caching_topic);
+		} else {
+			ast_log(LOG_ERROR, "stasis_caching_topic unsubscribed multiple times\n");
+		}
+	}
 }
 
 struct cache_entry {
@@ -146,7 +160,6 @@
 		/* Remove entry from cache */
 		cached_entry = ao2_find(caching_topic->cache, new_entry, OBJ_POINTER | OBJ_UNLINK);
 		old_snapshot = cached_entry->snapshot;
-		ao2_ref(old_snapshot, +1);
 	} else {
 		/* Insert/update cache */
 		SCOPED_AO2LOCK(lock, caching_topic->cache);
@@ -381,6 +394,7 @@
 	if (sub == NULL) {
 		return NULL;
 	}
+	caching_topic->sub = sub;
 
 	ao2_ref(caching_topic, +1);
 	return caching_topic;

Modified: team/dlee/stasis-core/tests/test_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/tests/test_stasis.c?view=diff&rev=382477&r1=382476&r2=382477
==============================================================================
--- team/dlee/stasis-core/tests/test_stasis.c (original)
+++ team/dlee/stasis-core/tests/test_stasis.c Tue Mar  5 16:35:53 2013
@@ -406,7 +406,7 @@
 {
 	RAII_VAR(struct stasis_message_type *, non_cache_type, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_topic *, topic, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, stasis_caching_unsubscribe);
 	RAII_VAR(struct consumer *, consumer, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
 	RAII_VAR(struct stasis_message *, test_message, NULL, ao2_cleanup);
@@ -455,7 +455,7 @@
 {
 	RAII_VAR(struct stasis_message_type *, cache_type, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_topic *, topic, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, stasis_caching_unsubscribe);
 	RAII_VAR(struct consumer *, consumer, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
 	RAII_VAR(struct stasis_message *, test_message1_1, NULL, ao2_cleanup);




More information about the asterisk-commits mailing list