*/
static int basic_hangup_hook(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *hook_pvt)
{
-/* BUGBUG Race condition. If all parties but one hangup at the same time, the bridge may not be dissolved on the remaining party. */
+ int bridge_count = 0;
+ struct ast_bridge_channel *iter;
+
ast_bridge_channel_lock_bridge(bridge_channel);
- if (2 < bridge_channel->bridge->num_channels) {
+ AST_LIST_TRAVERSE(&bridge->channels, iter, entry) {
+ if (iter != bridge_channel && iter->state == AST_BRIDGE_CHANNEL_STATE_WAIT) {
+ ++bridge_count;
+ }
+ }
+ if (2 <= bridge_count) {
/* Just allow this channel to leave the multi-party bridge. */
ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
}