[asterisk-commits] dlee: branch dlee/stasis-core r382487 - in /team/dlee/stasis-core: main/ tests/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 6 08:51:03 CST 2013


Author: dlee
Date: Wed Mar  6 08:50:59 2013
New Revision: 382487

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382487
Log:
Backported kmoore's leak fixes from r382481 to r382485

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

Modified: team/dlee/stasis-core/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/stasis.c?view=diff&rev=382487&r1=382486&r2=382487
==============================================================================
--- team/dlee/stasis-core/main/stasis.c (original)
+++ team/dlee/stasis-core/main/stasis.c Wed Mar  6 08:50:59 2013
@@ -122,7 +122,7 @@
 	sub->uniqueid = NULL;
 	ao2_cleanup(sub->topic);
 	sub->topic = NULL;
-	ao2_cleanup(sub->mailbox);
+	ast_taskprocessor_unreference(sub->mailbox);
 	sub->mailbox = NULL;
 }
 

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=382487&r1=382486&r2=382487
==============================================================================
--- team/dlee/stasis-core/main/stasis_cache.c (original)
+++ team/dlee/stasis-core/main/stasis_cache.c Wed Mar  6 08:50:59 2013
@@ -149,7 +149,7 @@
 {
 	RAII_VAR(struct cache_entry *, new_entry, NULL, ao2_cleanup);
 	RAII_VAR(struct cache_entry *, cached_entry, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_message *, old_snapshot, NULL, ao2_cleanup);
+	struct stasis_message *old_snapshot = NULL;
 
 	ast_assert(caching_topic->cache != NULL);
 
@@ -158,7 +158,10 @@
 	if (new_snapshot == NULL) {
 		/* Remove entry from cache */
 		cached_entry = ao2_find(caching_topic->cache, new_entry, OBJ_POINTER | OBJ_UNLINK);
-		old_snapshot = cached_entry->snapshot;
+		if (cached_entry) {
+			old_snapshot = cached_entry->snapshot;
+			cached_entry->snapshot = NULL;
+		}
 	} else {
 		/* Insert/update cache */
 		SCOPED_AO2LOCK(lock, caching_topic->cache);
@@ -176,11 +179,6 @@
 
 	}
 
-	if (!old_snapshot) {
-		return NULL;
-	}
-
-	ao2_ref(old_snapshot, +1);
 	return old_snapshot;
 }
 

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=382487&r1=382486&r2=382487
==============================================================================
--- team/dlee/stasis-core/tests/test_stasis.c (original)
+++ team/dlee/stasis-core/tests/test_stasis.c Wed Mar  6 08:50:59 2013
@@ -565,7 +565,6 @@
 	RAII_VAR(struct stasis_message *, test_message1_clear, NULL, ao2_cleanup);
 	int actual_len;
 	struct stasis_cache_update *actual_update;
-	struct stasis_message *actual_message;
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -607,8 +606,9 @@
 	ast_test_validate(test, topic == actual_update->topic);
 	ast_test_validate(test, NULL == actual_update->old_snapshot);
 	ast_test_validate(test, test_message1_1 == actual_update->new_snapshot);
-	actual_message = stasis_cache_get(caching_topic, cache_type, "1");
-	ast_test_validate(test, test_message1_1 == actual_message);
+	ast_test_validate(test, test_message1_1 == stasis_cache_get(caching_topic, cache_type, "1"));
+	/* stasis_cache_get returned a ref, so unref test_message1_1 */
+	ao2_ref(test_message1_1, -1);
 
 	ast_test_validate(test, stasis_cache_update() == stasis_message_type(consumer->messages_rxed[1]));
 	actual_update = stasis_message_data(consumer->messages_rxed[1]);
@@ -616,6 +616,8 @@
 	ast_test_validate(test, NULL == actual_update->old_snapshot);
 	ast_test_validate(test, test_message2_1 == actual_update->new_snapshot);
 	ast_test_validate(test, test_message2_1 == stasis_cache_get(caching_topic, cache_type, "2"));
+	/* stasis_cache_get returned a ref, so unref test_message2_1 */
+	ao2_ref(test_message2_1, -1);
 
 	/* Update snapshot 2 */
 	test_message2_2 = cache_test_message_create(cache_type, "2", "2");
@@ -630,6 +632,8 @@
 	ast_test_validate(test, test_message2_1 == actual_update->old_snapshot);
 	ast_test_validate(test, test_message2_2 == actual_update->new_snapshot);
 	ast_test_validate(test, test_message2_2 == stasis_cache_get(caching_topic, cache_type, "2"));
+	/* stasis_cache_get returned a ref, so unref test_message2_2 */
+	ao2_ref(test_message2_2, -1);
 
 	/* Clear snapshot 1 */
 	test_message1_clear = stasis_cache_clear_create(cache_type, "1");




More information about the asterisk-commits mailing list