[Asterisk-code-review] stasis endpoints: Remove silly usage of RAII VAR. (asterisk[master])

Corey Farrell asteriskteam at digium.com
Tue Jan 9 20:36:52 CST 2018


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


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

stasis_endpoints: Remove silly usage of RAII_VAR.

Change-Id: Ic099dc552f36c353c89783a4bcfd09f010432733
---
M main/stasis_endpoints.c
1 file changed, 25 insertions(+), 16 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/13/7913/1

diff --git a/main/stasis_endpoints.c b/main/stasis_endpoints.c
index 5cee22e..336da49 100644
--- a/main/stasis_endpoints.c
+++ b/main/stasis_endpoints.c
@@ -305,8 +305,8 @@
 struct stasis_message *ast_endpoint_blob_create(struct ast_endpoint *endpoint,
 	struct stasis_message_type *type, struct ast_json *blob)
 {
-	RAII_VAR(struct ast_endpoint_blob *, obj, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	struct ast_endpoint_blob *obj;
+	struct stasis_message *msg;
 
 	if (!type) {
 		return NULL;
@@ -321,37 +321,40 @@
 
 	if (endpoint) {
 		if (!(obj->snapshot = ast_endpoint_snapshot_create(endpoint))) {
+			ao2_ref(obj, -1);
+
 			return NULL;
 		}
 	}
 
 	obj->blob = ast_json_ref(blob);
+	msg = stasis_message_create(type, obj);
+	ao2_ref(obj, -1);
 
-	if (!(msg = stasis_message_create(type, obj))) {
-		return NULL;
-	}
-
-	ao2_ref(msg, +1);
 	return msg;
 }
 
 void ast_endpoint_blob_publish(struct ast_endpoint *endpoint, struct stasis_message_type *type,
 	struct ast_json *blob)
 {
-	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	if (blob) {
-		message = ast_endpoint_blob_create(endpoint, type, blob);
+	struct stasis_message *message;
+
+	if (!blob) {
+		return;
 	}
+
+	message = ast_endpoint_blob_create(endpoint, type, blob);
 	if (message) {
 		stasis_publish(ast_endpoint_topic(endpoint), message);
+		ao2_ref(message, -1);
 	}
 }
 
 struct ast_endpoint_snapshot *ast_endpoint_latest_snapshot(const char *tech,
 	const char *name)
 {
-	RAII_VAR(char *, id, NULL, ast_free);
-	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	char *id = NULL;
+	struct stasis_message *msg;
 	struct ast_endpoint_snapshot *snapshot;
 
 	if (ast_strlen_zero(name)) {
@@ -364,8 +367,8 @@
 	}
 	ast_tech_to_upper(id);
 
-	msg = stasis_cache_get(ast_endpoint_cache(),
-		ast_endpoint_snapshot_type(), id);
+	msg = stasis_cache_get(ast_endpoint_cache(), ast_endpoint_snapshot_type(), id);
+	ast_free(id);
 	if (!msg) {
 		return NULL;
 	}
@@ -374,6 +377,8 @@
 	ast_assert(snapshot != NULL);
 
 	ao2_ref(snapshot, +1);
+	ao2_ref(msg, -1);
+
 	return snapshot;
 }
 
@@ -406,7 +411,7 @@
 	const struct ast_endpoint_snapshot *snapshot,
 	const struct stasis_message_sanitizer *sanitize)
 {
-	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+	struct ast_json *json;
 	struct ast_json *channel_array;
 	int i;
 
@@ -424,6 +429,8 @@
 		int res = ast_json_object_set(json, "max_channels",
 			ast_json_integer_create(snapshot->max_channels));
 		if (res != 0) {
+			ast_json_unref(json);
+
 			return NULL;
 		}
 	}
@@ -441,11 +448,13 @@
 		res = ast_json_array_append(channel_array,
 			ast_json_string_create(snapshot->channel_ids[i]));
 		if (res != 0) {
+			ast_json_unref(json);
+
 			return NULL;
 		}
 	}
 
-	return ast_json_ref(json);
+	return json;
 }
 
 static void endpoints_stasis_cleanup(void)

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic099dc552f36c353c89783a4bcfd09f010432733
Gerrit-Change-Number: 7913
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/20180109/dc565a8b/attachment.html>


More information about the asterisk-code-review mailing list