Skip to content

Commit

Permalink
bridge: Unlock channel during Local peer check.
Browse files Browse the repository at this point in the history
It's not safe to keep the channel locked while locking
the peer Local channel, as it can result in a deadlock.

This change unlocks it during this time but keeps the
bridge locked to ensure nothing changes about the bridge.

ASTERISK-29821

Change-Id: Ib68eb7037e5a479bcc2aceee77337cdde1fbdde6
  • Loading branch information
jcolp committed Jan 5, 2022
1 parent 2b61440 commit f9e6794
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main/bridge_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2861,11 +2861,13 @@ int bridge_channel_internal_join(struct ast_bridge_channel *bridge_channel)
ast_bridge_lock(bridge_channel->bridge);

ast_channel_lock(bridge_channel->chan);

peer = ast_local_get_peer(bridge_channel->chan);

if (peer) {
struct ast_bridge *peer_bridge;

ast_channel_unlock(bridge_channel->chan);

ast_channel_lock(peer);
peer_bridge = ast_channel_internal_bridge(peer);
ast_channel_unlock(peer);
Expand All @@ -2875,14 +2877,15 @@ int bridge_channel_internal_join(struct ast_bridge_channel *bridge_channel)
* to be reference counted or locked.
*/
if (peer_bridge == bridge_channel->bridge) {
ast_channel_unlock(bridge_channel->chan);
ast_bridge_unlock(bridge_channel->bridge);
ast_debug(1, "Bridge %s: %p(%s) denying Bridge join to prevent Local channel loop\n",
bridge_channel->bridge->uniqueid,
bridge_channel,
ast_channel_name(bridge_channel->chan));
return -1;
}

ast_channel_lock(bridge_channel->chan);
}

bridge_channel->read_format = ao2_bump(ast_channel_readformat(bridge_channel->chan));
Expand Down

0 comments on commit f9e6794

Please sign in to comment.