From: Mike Bradeen Date: Tue, 18 Feb 2025 22:17:07 +0000 (-0700) Subject: bridge_channel: don't set cause code on channel during bridge delete if already set X-Git-Tag: 20.13.0-rc1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d73e13901364ba632cc27f8a677412c53057b515;p=thirdparty%2Fasterisk.git bridge_channel: don't set cause code on channel during bridge delete if already set Due to a potential race condition via ARI when hanging up a channel hangup with cause while also deleting a bridge containing that channel, the bridge delete can over-write the hangup cause code resulting in Normal Call Clearing instead of the set value. With this change, bridge deletion will only set the hangup code if it hasn't been previously set. Resolves: #1124 (cherry picked from commit a39f3d5adb1b6918225af79eafe6e91723913c2d) --- diff --git a/main/bridge_channel.c b/main/bridge_channel.c index a0334b808f..60781abd8b 100644 --- a/main/bridge_channel.c +++ b/main/bridge_channel.c @@ -278,13 +278,23 @@ static void bridge_channel_poke(struct ast_bridge_channel *bridge_channel) */ static int channel_set_cause(struct ast_channel *chan, int cause) { + int current_cause; ast_channel_lock(chan); + current_cause = ast_channel_hangupcause(chan); + + /* if the hangupcause is already set, leave it */ + if (current_cause > 0) { + ast_channel_unlock(chan); + return current_cause; + } + if (cause <= 0) { cause = ast_channel_hangupcause(chan); if (cause <= 0) { cause = AST_CAUSE_NORMAL_CLEARING; } } + ast_channel_hangupcause_set(chan, cause); ast_channel_unlock(chan); return cause;