[Asterisk-code-review] Stasis: Use control queue to prevent crash. (asterisk[13])

Mark Michelson asteriskteam at digium.com
Thu Jan 21 11:03:30 CST 2016


Mark Michelson has uploaded a new change for review.

  https://gerrit.asterisk.org/2056

Change subject: Stasis: Use control queue to prevent crash.
......................................................................

Stasis: Use control queue to prevent crash.

A crash occurred when attempting to set a channel variable on a channel
that had already been hung up. This is because there is a small window
between when a control is grabbed and when the channel variable is set
that the channel can be hung up.

The fix here is to queue the setting of the channel variable onto the
control queue. This way, the manipulation of the channel happens in a
thread where it is safe to be done.

In this change, I also noticed that the setting of bridge roles on
channels was being done outside of the control queue, so I also changed
those operations to be done in the control queue.

ASTERISK-25709 #close
Reported by Mark Michelson

Change-Id: I2a0a4d51bce6fba6f1d9954e40935e42f366ea78
---
M res/stasis/control.c
1 file changed, 46 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/56/2056/1

diff --git a/res/stasis/control.c b/res/stasis/control.c
index 87362df..daeb851 100644
--- a/res/stasis/control.c
+++ b/res/stasis/control.c
@@ -355,14 +355,38 @@
 	return 0;
 }
 
+static int app_control_add_role(struct stasis_app_control *control,
+		struct ast_channel *chan, void *data)
+{
+	char *role = data;
+
+	return ast_channel_add_bridge_role(chan, role);
+}
+
 int stasis_app_control_add_role(struct stasis_app_control *control, const char *role)
 {
-	return ast_channel_add_bridge_role(control->channel, role);
+	char *role_dup;
+
+	role_dup = ast_strdup(role);
+	if (!role_dup) {
+		return -1;
+	}
+
+	stasis_app_send_command_async(control, app_control_add_role, role_dup, ast_free_ptr);
+	return 0;
+}
+
+static int app_control_clear_roles(struct stasis_app_control *control,
+		struct ast_channel *chan, void *data)
+{
+	ast_channel_clear_bridge_roles(chan);
+
+	return 0;
 }
 
 void stasis_app_control_clear_roles(struct stasis_app_control *control)
 {
-	ast_channel_clear_bridge_roles(control->channel);
+	stasis_app_send_command_async(control, app_control_clear_roles, NULL, NULL);
 }
 
 int control_command_count(struct stasis_app_control *control)
@@ -598,9 +622,28 @@
 	return 0;
 }
 
+static int app_control_set_channel_var(struct stasis_app_control *control,
+	struct ast_channel *chan, void *data)
+{
+	struct ast_variable *var = data;
+
+	pbx_builtin_setvar_helper(control->channel, var->name, var->value);
+
+	return 0;
+}
+
 int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value)
 {
-	return pbx_builtin_setvar_helper(control->channel, variable, value);
+	struct ast_variable *var;
+
+	var = ast_variable_new(variable, value, "ARI");
+	if (!var) {
+		return -1;
+	}
+
+	stasis_app_send_command_async(control, app_control_set_channel_var, var, ast_free_ptr);
+
+	return 0;
 }
 
 static int app_control_hold(struct stasis_app_control *control,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a0a4d51bce6fba6f1d9954e40935e42f366ea78
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list