[Asterisk-code-review] stasis cache pattern: Remove silly usage of RAII VAR. (asterisk[15])

Corey Farrell asteriskteam at digium.com
Wed Jan 10 16:01:08 CST 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/7926


Change subject: stasis_cache_pattern: Remove silly usage of RAII_VAR.
......................................................................

stasis_cache_pattern: Remove silly usage of RAII_VAR.

Change-Id: Ic98a51f555062cd863b6db3f8d76065943a9dea3
---
M main/stasis_cache_pattern.c
1 file changed, 22 insertions(+), 15 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/26/7926/1

diff --git a/main/stasis_cache_pattern.c b/main/stasis_cache_pattern.c
index 724b307..f0e34b9 100644
--- a/main/stasis_cache_pattern.c
+++ b/main/stasis_cache_pattern.c
@@ -65,8 +65,8 @@
 struct stasis_cp_all *stasis_cp_all_create(const char *name,
 	snapshot_get_id id_fn)
 {
-	RAII_VAR(char *, cached_name, NULL, ast_free);
-	RAII_VAR(struct stasis_cp_all *, all, NULL, ao2_cleanup);
+	char *cached_name = NULL;
+	struct stasis_cp_all *all;
 
 	all = ao2_t_alloc(sizeof(*all), all_dtor, name);
 	if (!all) {
@@ -75,21 +75,25 @@
 
 	ast_asprintf(&cached_name, "%s-cached", name);
 	if (!cached_name) {
+		ao2_ref(all, -1);
+
 		return NULL;
 	}
 
 	all->topic = stasis_topic_create(name);
 	all->topic_cached = stasis_topic_create(cached_name);
+	ast_free(cached_name);
 	all->cache = stasis_cache_create(id_fn);
 	all->forward_all_to_cached =
 		stasis_forward_all(all->topic, all->topic_cached);
 
 	if (!all->topic || !all->topic_cached || !all->cache ||
 		!all->forward_all_to_cached) {
+		ao2_ref(all, -1);
+
 		return NULL;
 	}
 
-	ao2_ref(all, +1);
 	return all;
 }
 
@@ -134,7 +138,7 @@
 struct stasis_cp_single *stasis_cp_single_create(struct stasis_cp_all *all,
 	const char *name)
 {
-	RAII_VAR(struct stasis_cp_single *, one, NULL, ao2_cleanup);
+	struct stasis_cp_single *one;
 
 	one = stasis_cp_sink_create(all, name);
 	if (!one) {
@@ -142,23 +146,22 @@
 	}
 
 	one->forward_topic_to_all = stasis_forward_all(one->topic, all->topic);
-	if (!one->forward_topic_to_all) {
-		return NULL;
-	}
 	one->forward_cached_to_all = stasis_forward_all(
 		stasis_caching_get_topic(one->topic_cached), all->topic_cached);
-	if (!one->forward_cached_to_all) {
+
+	if (!one->forward_topic_to_all || !one->forward_cached_to_all) {
+		ao2_ref(one, -1);
+
 		return NULL;
 	}
 
-	ao2_ref(one, +1);
 	return one;
 }
 
 struct stasis_cp_single *stasis_cp_sink_create(struct stasis_cp_all *all,
 	const char *name)
 {
-	RAII_VAR(struct stasis_cp_single *, one, NULL, ao2_cleanup);
+	struct stasis_cp_single *one;
 
 	one = ao2_t_alloc(sizeof(*one), one_dtor, name);
 	if (!one) {
@@ -167,14 +170,18 @@
 
 	one->topic = stasis_topic_create(name);
 	if (!one->topic) {
-		return NULL;
-	}
-	one->topic_cached = stasis_caching_topic_create(one->topic, all->cache);
-	if (!one->topic_cached) {
+		ao2_ref(one, -1);
+
 		return NULL;
 	}
 
-	ao2_ref(one, +1);
+	one->topic_cached = stasis_caching_topic_create(one->topic, all->cache);
+	if (!one->topic_cached) {
+		ao2_ref(one, -1);
+
+		return NULL;
+	}
+
 	return one;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/7926
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic98a51f555062cd863b6db3f8d76065943a9dea3
Gerrit-Change-Number: 7926
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180110/17c788f8/attachment-0001.html>


More information about the asterisk-code-review mailing list