[Asterisk-code-review] bridges/bridge simple.c: Protect calls to ast channel get st... (asterisk[master])

Jasper van der Neut asteriskteam at digium.com
Fri Feb 16 02:55:00 CST 2018


Jasper van der Neut has uploaded this change for review. ( https://gerrit.asterisk.org/8220


Change subject: bridges/bridge_simple.c: Protect calls to ast_channel_get_stream_topology
......................................................................

bridges/bridge_simple.c: Protect calls to ast_channel_get_stream_topology

When calling ast_channel_get_stream_topology the channel must be locked.

ASTERISK-27259

Change-Id: I4f8766f0710765e0e88758c2a7aca33fa25ec0f7
---
M bridges/bridge_simple.c
1 file changed, 22 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/20/8220/1

diff --git a/bridges/bridge_simple.c b/bridges/bridge_simple.c
index 7ee1966..34a690c 100644
--- a/bridges/bridge_simple.c
+++ b/bridges/bridge_simple.c
@@ -116,11 +116,20 @@
 static void simple_bridge_request_stream_topology_change(struct ast_channel *chan,
 	struct ast_stream_topology *requested_topology)
 {
-	struct ast_stream_topology *existing_topology = ast_channel_get_stream_topology(chan);
+	struct ast_stream_topology *existing_topology = NULL;
 	struct ast_stream *stream;
 	struct ast_format_cap *audio_formats = NULL;
 	struct ast_stream_topology *new_topology;
 	int i;
+
+	ast_channel_lock(chan);
+	existing_topology = ast_stream_topology_clone(ast_channel_get_stream_topology(chan));
+	ast_channel_unlock(chan);
+
+	if (!existing_topology) {
+		ast_channel_request_stream_topology_change(chan, requested_topology, &simple_bridge);
+		return;
+	}
 
 	/* We find an existing stream with negotiated audio formats that we can place into
 	 * any audio streams in the new topology to ensure that negotiation succeeds. Some
@@ -137,6 +146,8 @@
 		audio_formats = ast_stream_get_formats(stream);
 		break;
 	}
+
+	ast_stream_topology_free(existing_topology);
 
 	if (!audio_formats) {
 		ast_channel_request_stream_topology_change(chan, requested_topology, &simple_bridge);
@@ -170,8 +181,8 @@
 {
 	struct ast_channel *c0 = AST_LIST_FIRST(&bridge->channels)->chan;
 	struct ast_channel *c1 = AST_LIST_LAST(&bridge->channels)->chan;
-	struct ast_stream_topology *t0 = ast_channel_get_stream_topology(c0);
-	struct ast_stream_topology *t1 = ast_channel_get_stream_topology(c1);
+	struct ast_stream_topology *t0 = NULL;
+	struct ast_stream_topology *t1 = NULL;
 
 	if (bridge_channel) {
 		ast_bridge_channel_stream_map(bridge_channel);
@@ -185,6 +196,14 @@
 		return;
 	}
 
+	ast_channel_lock(c0);
+	t0 = ast_channel_get_stream_topology(c0);
+	ast_channel_unlock(c0);
+
+	ast_channel_lock(c1);
+	t1 = ast_channel_get_stream_topology(c1);
+	ast_channel_unlock(c1);
+
 	/* Align topologies according to size or first channel to join */
 	if (ast_stream_topology_get_count(t0) < ast_stream_topology_get_count(t1)) {
 		simple_bridge_request_stream_topology_change(c0, t1);

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f8766f0710765e0e88758c2a7aca33fa25ec0f7
Gerrit-Change-Number: 8220
Gerrit-PatchSet: 1
Gerrit-Owner: Jasper van der Neut <jasper at isotopic.nl>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180216/f8f178d6/attachment.html>


More information about the asterisk-code-review mailing list