From fca3bc9199e899df2f2e809e280bdc79ca082834 Mon Sep 17 00:00:00 2001
From: Markus Gothe <markus.gothe@genexis.eu>
Date: Tue, 21 Dec 2021 16:32:50 +0100
Subject: [PATCH] Fix NULL-pointer issue with RTP stats.

When we originate a call from an extension to another we
get a NULL pointer issue when going on hook.

Enable CONFIG_PACKAGE_asterisk-res-clioriginate and then
use the command below:

asterisk -rx 'channel originate local/#123457@local_extensions
extension 0000@local_extensions'

After going on hook on the FXS port, which is mapped to extension
0000, there will be a segmentation fault because the other channel
doesn't implement the getRtpStats() function pointer.
---
 main/bridge_channel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/main/bridge_channel.c b/main/bridge_channel.c
index ffacbed1dc..74a7a01690 100644
--- a/main/bridge_channel.c
+++ b/main/bridge_channel.c
@@ -315,7 +315,8 @@ void ast_bridge_channel_leave_bridge(struct ast_bridge_channel *bridge_channel,
 {
 	ast_bridge_channel_lock(bridge_channel);
 	ast_bridge_channel_leave_bridge_nolock(bridge_channel, new_state, cause);
-	ast_channel_tech(bridge_channel->chan)->getRtpStats(bridge_channel->chan);
+	if (ast_channel_tech(bridge_channel->chan)->getRtpStats != NULL)
+		ast_channel_tech(bridge_channel->chan)->getRtpStats(bridge_channel->chan);
 	ast_bridge_channel_unlock(bridge_channel);
 }
 
-- 
GitLab