mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-03 03:02:15 +00:00
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 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@404237 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user