[Asterisk-code-review] stasis: Fix leaks (...asterisk[master])

Friendly Automation asteriskteam at digium.com
Mon Sep 23 13:05:38 CDT 2019


Friendly Automation has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/12907 )

Change subject: stasis: Fix leaks
......................................................................

stasis: Fix leaks

* Release reference returned by cache_remove
* state_alloc unconditionally bumped state_topic even when it was
  locally allocated.

Change-Id: I51101bf7d07b8dc8ce8fc46b6cb31fbbd213fbc7
---
M main/stasis_cache.c
M main/stasis_state.c
2 files changed, 8 insertions(+), 8 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/main/stasis_cache.c b/main/stasis_cache.c
index 6be4bf1..bcd7e7d 100644
--- a/main/stasis_cache.c
+++ b/main/stasis_cache.c
@@ -868,7 +868,7 @@
 			ao2_wrlock(caching_topic->cache->entries);
 			sub = cache_find(caching_topic->cache->entries, stasis_subscription_change_type(), change->uniqueid);
 			if (sub) {
-				cache_remove(caching_topic->cache->entries, sub, stasis_message_eid(message));
+				ao2_cleanup(cache_remove(caching_topic->cache->entries, sub, stasis_message_eid(message)));
 				ao2_cleanup(sub);
 			}
 			ao2_unlock(caching_topic->cache->entries);
diff --git a/main/stasis_state.c b/main/stasis_state.c
index a915972..aa00f9a 100644
--- a/main/stasis_state.c
+++ b/main/stasis_state.c
@@ -165,6 +165,13 @@
 			return NULL;
 		}
 		ast_free(name);
+	} else {
+		/*
+		 * Since the state topic was passed in, go ahead and bump its reference.
+		 * By doing this here first, it allows us to consistently decrease the reference on
+		 * state allocation error.
+		 */
+		ao2_ref(state_topic, +1);
 	}
 
 	if (!id) {
@@ -175,13 +182,6 @@
 		id = state_id_by_topic(manager->all_topic, state_topic);
 	}
 
-	/*
-	 * Since the state topic could have been passed in, go ahead and bump its reference.
-	 * By doing this here first, it allows us to consistently decrease the reference on
-	 * state allocation error.
-	 */
-	ao2_ref(state_topic, +1);
-
 	state = ao2_alloc(sizeof(*state) + strlen(id) + 1, state_dtor);
 	if (!state) {
 		ast_log(LOG_ERROR, "Unable to allocate state '%s' in manager '%s'\n",

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12907
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I51101bf7d07b8dc8ce8fc46b6cb31fbbd213fbc7
Gerrit-Change-Number: 12907
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190923/e8cf2001/attachment.html>


More information about the asterisk-code-review mailing list