[Asterisk-code-review] res ari events: Fix JSON leak in stasis app message handler. (asterisk[15])

Corey Farrell asteriskteam at digium.com
Mon Nov 6 15:53:33 CST 2017


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


Change subject: res_ari_events: Fix JSON leak in stasis_app_message_handler.
......................................................................

res_ari_events: Fix JSON leak in stasis_app_message_handler.

The only time we didn't leak the JSON object is when no client was
connected and we successfully added the message to the queue.

Change-Id: I82696df8fe723b3365c15c3f7089501da8daa892
---
M res/ari/resource_events.c
1 file changed, 9 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/48/7048/1

diff --git a/res/ari/resource_events.c b/res/ari/resource_events.c
index 4be5d02..447af10 100644
--- a/res/ari/resource_events.c
+++ b/res/ari/resource_events.c
@@ -108,11 +108,14 @@
 		        msg_application);
 	} else if (!session->ws_session) {
 		/* If the websocket is NULL, the message goes to the queue */
-		AST_VECTOR_APPEND(&session->message_queue, message);
-		ast_log(LOG_WARNING,
-				"Queued '%s' message for Stasis app '%s'; websocket is not ready\n",
-				msg_type,
-				msg_application);
+		if (!AST_VECTOR_APPEND(&session->message_queue, message)) {
+			ast_log(LOG_WARNING,
+					"Queued '%s' message for Stasis app '%s'; websocket is not ready\n",
+					msg_type,
+					msg_application);
+			/* This is the only path that we don't free message. */
+			message = NULL;
+		}
 	} else {
 		if (stasis_app_get_debug_by_name(app_name)) {
 			char *str = ast_json_dump_string_format(message, ast_ari_json_format());
@@ -126,6 +129,7 @@
 		/* We are ready to publish the message */
 		ast_ari_websocket_session_write(session->ws_session, message);
 	}
+	ast_json_unref(message);
 
 	ao2_unlock(session);
 }

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

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82696df8fe723b3365c15c3f7089501da8daa892
Gerrit-Change-Number: 7048
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/20171106/0cc42ccc/attachment.html>


More information about the asterisk-code-review mailing list