[Asterisk-code-review] Stasis/ARI: Fix off-nominal path json memory leaks. (asterisk[master])

Joshua Colp asteriskteam at digium.com
Mon Nov 6 08:15:03 CST 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/6986 )

Change subject: Stasis/ARI: Fix off-nominal path json memory leaks.
......................................................................

Stasis/ARI: Fix off-nominal path json memory leaks.

Change-Id: Id569c624c426e3b22a99936473c730592d8b83fb
---
M main/sorcery.c
M res/ari/resource_asterisk.c
M res/ari/resource_sounds.c
M res/res_ari.c
M res/stasis/messaging.c
5 files changed, 15 insertions(+), 2 deletions(-)

Approvals:
  Sean Bright: Looks good to me, but someone else must approve
  Matthew Fredrickson: Looks good to me, but someone else must approve
  Corey Farrell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/main/sorcery.c b/main/sorcery.c
index 6694167..01b7791 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -1633,6 +1633,7 @@
 	int res = 0;
 
 	if (!object_type || !json) {
+		ast_json_unref(json);
 		return NULL;
 	}
 
diff --git a/res/ari/resource_asterisk.c b/res/ari/resource_asterisk.c
index e76eb02..5c6a35a 100644
--- a/res/ari/resource_asterisk.c
+++ b/res/ari/resource_asterisk.c
@@ -433,6 +433,10 @@
 	struct ast_json *json;
 
 	json = ast_json_array_create();
+	if (!json) {
+		ast_ari_response_alloc_failed(response);
+		return;
+	}
 	ast_update_module_list_data(&process_module_list, NULL, json);
 
 	ast_ari_response_ok(response, json);
@@ -505,6 +509,7 @@
 		ast_ari_response_error(
 			response, 409, "Conflict",
 			"Module information could not be retrieved");
+		ast_json_unref(json);
 		return;
 	}
 
@@ -667,10 +672,12 @@
 	if (res == AST_LOGGER_FAILURE) {
 		ast_ari_response_error(response, 500, "Internal Server Error",
 			"Response body is not valid");
+		ast_json_unref(json);
 		return;
 	} else if (res == AST_LOGGER_ALLOC_ERROR) {
 		ast_ari_response_error(response, 500, "Internal Server Error",
 			"Allocation Failed");
+		ast_json_unref(json);
 		return;
 	}
 
diff --git a/res/ari/resource_sounds.c b/res/ari/resource_sounds.c
index 59ace5d..2cb35b6 100644
--- a/res/ari/resource_sounds.c
+++ b/res/ari/resource_sounds.c
@@ -202,6 +202,7 @@
 
 	if (!ast_json_array_size(sounds_blob)) {
 		ast_ari_response_error(response, 404, "Not Found", "No sounds found that matched the query");
+		ast_json_unref(sounds_blob);
 		return;
 	}
 
diff --git a/res/res_ari.c b/res/res_ari.c
index 5145499..7c12d39 100644
--- a/res/res_ari.c
+++ b/res/res_ari.c
@@ -984,9 +984,11 @@
 		struct ast_str *buf = ast_str_create(512);
 		char *str = ast_json_dump_string_format(body, ast_ari_json_format());
 
-		if (!buf) {
+		if (!buf || !str) {
 			ast_http_request_close_on_completion(ser);
 			ast_http_error(ser, 500, "Server Error", "Out of memory");
+			ast_json_free(str);
+			ast_free(buf);
 			goto request_failed;
 		}
 
diff --git a/res/stasis/messaging.c b/res/stasis/messaging.c
index 8dfd996..d398bb6 100644
--- a/res/stasis/messaging.c
+++ b/res/stasis/messaging.c
@@ -264,6 +264,7 @@
 
 	json_vars = ast_json_array_create();
 	if (!json_vars) {
+		ast_msg_var_iterator_destroy(it_vars);
 		return NULL;
 	}
 
@@ -272,7 +273,8 @@
 
 		json_tuple = ast_json_pack("{s: s}", name, value);
 		if (!json_tuple) {
-			ast_json_free(json_vars);
+			ast_json_unref(json_vars);
+			ast_msg_var_iterator_destroy(it_vars);
 			return NULL;
 		}
 

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id569c624c426e3b22a99936473c730592d8b83fb
Gerrit-Change-Number: 6986
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171106/eff60079/attachment-0001.html>


More information about the asterisk-code-review mailing list