[Asterisk-code-review] Fixed locking issue in stasis app bridge moh channel (asterisk[15])

Moritz Fain asteriskteam at digium.com
Tue Jun 26 09:18:45 CDT 2018


Moritz Fain has uploaded this change for review. ( https://gerrit.asterisk.org/9297


Change subject: Fixed locking issue in stasis_app_bridge_moh_channel
......................................................................

Fixed locking issue in stasis_app_bridge_moh_channel

Fixed an issue that resulted in "Allocation failed" when
using ARI to start playing MOH on a bridge.

ASTERISK-26094 #close

Change-Id: Ibff479e167b3320c68aaabfada7e1d0ef7bd548c
---
M res/res_stasis.c
1 file changed, 9 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/97/9297/1

diff --git a/res/res_stasis.c b/res/res_stasis.c
index a60ec5f..5eaed98 100644
--- a/res/res_stasis.c
+++ b/res/res_stasis.c
@@ -517,13 +517,19 @@
 /*! Provides the moh channel with a thread so it can actually play its music */
 static void *moh_channel_thread(void *data)
 {
-	struct ast_channel *moh_channel = data;
+	struct stasis_app_bridge_channel_wrapper *moh_wrapper = data;
+	struct ast_channel *moh_channel = ast_channel_get_by_name(moh_wrapper->channel_id);
 
 	while (!ast_safe_sleep(moh_channel, 1000)) {
 	}
 
+	ao2_lock(app_bridges_moh);
+	ao2_unlink_flags(app_bridges_moh, moh_wrapper, OBJ_NOLOCK);
+
 	ast_moh_stop(moh_channel);
 	ast_hangup(moh_channel);
+
+	ao2_unlock(app_bridges_moh);
 
 	return NULL;
 }
@@ -591,7 +597,7 @@
 		return NULL;
 	}
 
-	if (ast_pthread_create_detached(&threadid, NULL, moh_channel_thread, chan)) {
+	if (ast_pthread_create_detached(&threadid, NULL, moh_channel_thread, new_wrapper)) {
 		ast_log(LOG_ERROR, "Failed to create channel thread. Abandoning MOH channel creation.\n");
 		ao2_unlink_flags(app_bridges_moh, new_wrapper, OBJ_NOLOCK);
 		ast_hangup(chan);
@@ -611,12 +617,12 @@
 	if (!moh_wrapper) {
 		chan = bridge_moh_create(bridge);
 	}
-	ao2_unlock(app_bridges_moh);
 
 	if (moh_wrapper) {
 		chan = ast_channel_get_by_name(moh_wrapper->channel_id);
 		ao2_ref(moh_wrapper, -1);
 	}
+	ao2_unlock(app_bridges_moh);
 
 	return chan;
 }

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

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibff479e167b3320c68aaabfada7e1d0ef7bd548c
Gerrit-Change-Number: 9297
Gerrit-PatchSet: 1
Gerrit-Owner: Moritz Fain <moritz at fain.io>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180626/6ef5e051/attachment.html>


More information about the asterisk-code-review mailing list