[Asterisk-code-review] res stasis: Fix multiple leaks. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Wed Nov 8 04:59:15 CST 2017


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

Change subject: res_stasis: Fix multiple leaks.
......................................................................

res_stasis: Fix multiple leaks.

* res/stasis/app.c JSON passed to app_send needs to be released.
* res/stasis_message.c: objects leak if vector append fails.

Change-Id: I8dd5385b9f50a5cadf2b1d16efecffd6ddb4db4a
---
M res/stasis/app.c
M res/stasis/messaging.c
2 files changed, 17 insertions(+), 4 deletions(-)

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



diff --git a/res/stasis/app.c b/res/stasis/app.c
index 7d88c1b..1e885c6 100644
--- a/res/stasis/app.c
+++ b/res/stasis/app.c
@@ -591,6 +591,7 @@
 {
 	RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
 	struct ast_json *json_endpoint;
+	struct ast_json *message;
 	struct stasis_app *app = pvt;
 	char *tech;
 	char *resource;
@@ -616,11 +617,15 @@
 		return -1;
 	}
 
-	app_send(app, ast_json_pack("{s: s, s: o, s: o, s: o}",
+	message = ast_json_pack("{s: s, s: o, s: o, s: o}",
 		"type", "TextMessageReceived",
 		"timestamp", ast_json_timeval(ast_tvnow(), NULL),
 		"endpoint", json_endpoint,
-		"message", ast_json_ref(json_msg)));
+		"message", ast_json_ref(json_msg));
+	if (message) {
+		app_send(app, message);
+		ast_json_unref(message);
+	}
 
 	return 0;
 }
diff --git a/res/stasis/messaging.c b/res/stasis/messaging.c
index d2df3ff..979b687 100644
--- a/res/stasis/messaging.c
+++ b/res/stasis/messaging.c
@@ -459,7 +459,11 @@
 		ao2_link(endpoint_subscriptions, sub);
 	} else {
 		ast_rwlock_wrlock(&tech_subscriptions_lock);
-		AST_VECTOR_APPEND(&tech_subscriptions, ao2_bump(sub));
+		if (AST_VECTOR_APPEND(&tech_subscriptions, ao2_bump(sub))) {
+			/* Release the ao2_bump that was for the vector and allocation references. */
+			ao2_ref(sub, -2);
+			sub = NULL;
+		}
 		ast_rwlock_unlock(&tech_subscriptions_lock);
 	}
 
@@ -487,7 +491,11 @@
 		ao2_unlock(sub);
 		return -1;
 	}
-	AST_VECTOR_APPEND(&sub->applications, tuple);
+	if (AST_VECTOR_APPEND(&sub->applications, tuple)) {
+		ao2_ref(tuple, -1);
+		ao2_unlock(sub);
+		return -1;
+	}
 	ao2_unlock(sub);
 
 	ast_debug(3, "App '%s' subscribed to messages from endpoint '%s'\n", app_name, endpoint ? ast_endpoint_get_id(endpoint) : "-- ALL --");

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

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I8dd5385b9f50a5cadf2b1d16efecffd6ddb4db4a
Gerrit-Change-Number: 7060
Gerrit-PatchSet: 2
Gerrit-Owner: 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/20171108/a3ba1084/attachment-0001.html>


More information about the asterisk-code-review mailing list