]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
bridge_basic.c: Make sure that ast_bridge_channel is not destroyed while iterating...
authorTinet-mucw <mucw@ti-net.com.cn>
Fri, 14 Jun 2024 02:16:36 +0000 (19:16 -0700)
committerAsterisk Development Team <asteriskteam@digium.com>
Thu, 11 Jul 2024 13:22:18 +0000 (13:22 +0000)
From the gdb information, we can see that while iterating over bridge->channels, the ast_bridge_channel reference count is 0, indicating it has already been destroyed.Additionally, when ast_bridge_channel is removed from bridge->channels, the bridge is first locked. Therefore, locking the bridge before iterating over bridge->channels can resolve the race condition.

Resolves: https://github.com/asterisk/asterisk/issues/768
(cherry picked from commit a1d0dac6c681e7cd2a15634907f729a9fd76259c)

main/bridge_basic.c

index 38a9e6c17f7e54a9e925809ce750e923d355d233..da19b96b58daaf7960a991f6219c5c43045db1a4 100644 (file)
@@ -1856,7 +1856,9 @@ static void bridge_ringing(struct ast_bridge *bridge)
                .subclass.integer = AST_CONTROL_RINGING,
        };
 
+       ast_bridge_lock(bridge);
        ast_bridge_queue_everyone_else(bridge, NULL, &ringing);
+       ast_bridge_unlock(bridge);
 }
 
 /*!
@@ -1869,7 +1871,9 @@ static void bridge_hold(struct ast_bridge *bridge)
                .subclass.integer = AST_CONTROL_HOLD,
        };
 
+       ast_bridge_lock(bridge);
        ast_bridge_queue_everyone_else(bridge, NULL, &hold);
+       ast_bridge_unlock(bridge);
 }
 
 /*!
@@ -1882,7 +1886,9 @@ static void bridge_unhold(struct ast_bridge *bridge)
                .subclass.integer = AST_CONTROL_UNHOLD,
        };
 
+       ast_bridge_lock(bridge);
        ast_bridge_queue_everyone_else(bridge, NULL, &unhold);
+       ast_bridge_unlock(bridge);
 }
 
 /*!