From: Mark Michelson Date: Thu, 21 Jan 2016 16:58:02 +0000 (-0600) Subject: Stasis: Use control queue to prevent crash. X-Git-Tag: 13.8.0-rc1~110^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eedd77fda03a657375d106427bcd3838fa90ad86;p=thirdparty%2Fasterisk.git 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 --- diff --git a/res/stasis/control.c b/res/stasis/control.c index 87362df16c..936e5e143e 100644 --- a/res/stasis/control.c +++ b/res/stasis/control.c @@ -355,14 +355,39 @@ int stasis_app_control_dial(struct stasis_app_control *control, const char *endp 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 +623,28 @@ int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int d 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,