diff options
author | Kevin Harwell <kharwell@digium.com> | 2013-12-18 20:33:37 +0000 |
---|---|---|
committer | Kevin Harwell <kharwell@digium.com> | 2013-12-18 20:33:37 +0000 |
commit | 28c0cb28d0815e5e59ab99b60ac6b50e1ed9cbae (patch) | |
tree | b42967f4899ba28aea79b9a11827c814b95b62c8 /main/core_local.c | |
parent | 86b5e11607e2e3b7dcfb0b72d41b492ce868f31c (diff) |
channel locking: Add locking for channel snapshot creation
Original commit message by mmichelson (asterisk 12 r403311):
"This adds channel locks around calls to create channel snapshots as well
as other functions which operate on a channel and then end up
creating a channel snapshot. Functions that expect the channel to be
locked prior to being called have had their documentation updated to
indicate such."
The above was initially committed and then reverted at r403398. The problem
was found to be in core_local.c in the publish_local_bridge_message function.
The ast_unreal_lock_all function locks and adds a reference to the returned
channels and while they were being unlocked they were not being unreffed when
no longer needed. Fixed by unreffing the channels.
Also in bridge.c a lock was obtained on "other->chan", but then an attempt was
made to unlock "other" and not the previously locked channel. Fixed by
unlocking "other->chan"
(closes issue ASTERISK-22709)
Reported by: John Bigelow
........
Merged revisions 404237 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404260 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/core_local.c')
-rw-r--r-- | main/core_local.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/main/core_local.c b/main/core_local.c index 4a047032c..edf28399b 100644 --- a/main/core_local.c +++ b/main/core_local.c @@ -498,29 +498,32 @@ static void publish_local_bridge_message(struct local_pvt *p) RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); RAII_VAR(struct ast_channel_snapshot *, one_snapshot, NULL, ao2_cleanup); RAII_VAR(struct ast_channel_snapshot *, two_snapshot, NULL, ao2_cleanup); - SCOPED_AO2LOCK(lock, p); + struct ast_channel *owner; + struct ast_channel *chan; + + ast_unreal_lock_all(&p->base, &chan, &owner); blob = ast_json_pack("{s: s, s: s, s: b}", "context", p->context, "exten", p->exten, "can_optimize", !ast_test_flag(&p->base, AST_UNREAL_NO_OPTIMIZATION)); if (!blob) { - return; + goto end; } multi_blob = ast_multi_channel_blob_create(blob); if (!multi_blob) { - return; + goto end; } - one_snapshot = ast_channel_snapshot_create(p->base.owner); + one_snapshot = ast_channel_snapshot_create(owner); if (!one_snapshot) { - return; + goto end; } - two_snapshot = ast_channel_snapshot_create(p->base.chan); + two_snapshot = ast_channel_snapshot_create(chan); if (!two_snapshot) { - return; + goto end; } ast_multi_channel_blob_add_channel(multi_blob, "1", one_snapshot); @@ -528,10 +531,19 @@ static void publish_local_bridge_message(struct local_pvt *p) msg = stasis_message_create(ast_local_bridge_type(), multi_blob); if (!msg) { - return; + goto end; } - stasis_publish(ast_channel_topic(p->base.owner), msg); + stasis_publish(ast_channel_topic(owner), msg); + +end: + ast_channel_unlock(owner); + ast_channel_unref(owner); + + ast_channel_unlock(chan); + ast_channel_unref(chan); + + ao2_unlock(&p->base); } int ast_local_setup_bridge(struct ast_channel *ast, struct ast_bridge *bridge, struct ast_channel *swap, struct ast_bridge_features *features) |