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

Jenkins2 asteriskteam at digium.com
Thu Jan 11 05:42:48 CST 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7915 )

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(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Richard Mudgett: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/main/stasis_cache_pattern.c b/main/stasis_cache_pattern.c
index 3106cb3..2a2ea44 100644
--- a/main/stasis_cache_pattern.c
+++ b/main/stasis_cache_pattern.c
@@ -67,8 +67,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) {
@@ -77,21 +77,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;
 }
 
@@ -136,7 +140,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) {
@@ -144,23 +148,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) {
@@ -169,14 +172,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/7915
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic98a51f555062cd863b6db3f8d76065943a9dea3
Gerrit-Change-Number: 7915
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180111/f64736d2/attachment.html>


More information about the asterisk-code-review mailing list