<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13044">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Benjamin Keith Ford: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Crash during "pjsip show channelstats" execution<br><br>During execution "pjsip show channelstats" cli command by an<br>external module asterisk crashed. It seems this is a separate<br>thread running to fetch and print rtp stats. The crash happened on<br>the ao2_lock method, just before it going to read the rtp stats on<br>a rtp instance. According to gdb backtrace log, it seems the<br>session media was already cleaned up at that moment.<br><br>ASTERISK-28578<br><br>Change-Id: Ia918bfa3c8119060633e39b14852e8d983e0417e<br>---<br>M channels/pjsip/cli_commands.c<br>1 file changed, 23 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/pjsip/cli_commands.c b/channels/pjsip/cli_commands.c</span><br><span>index 514cf70..885b854 100644</span><br><span>--- a/channels/pjsip/cli_commands.c</span><br><span>+++ b/channels/pjsip/cli_commands.c</span><br><span>@@ -343,39 +343,52 @@</span><br><span> struct ast_sip_cli_context *context = arg;</span><br><span> const struct ast_channel_snapshot *snapshot = obj;</span><br><span> struct ast_channel *channel = ast_channel_get_by_name(snapshot->name);</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_sip_channel_pvt *cpvt = channel ? ast_channel_tech_pvt(channel) : NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- struct chan_pjsip_pvt *pvt = cpvt ? cpvt->pvt : NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_sip_session_media *media = pvt ? pvt->media[SIP_MEDIA_AUDIO] : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_channel_pvt *cpvt = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct chan_pjsip_pvt *pvt = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_session_media *media = NULL;</span><br><span> struct ast_rtp_instance_stats stats;</span><br><span> char *print_name = NULL;</span><br><span> char *print_time = alloca(32);</span><br><span> char codec_in_use[7];</span><br><span style="color: hsl(120, 100%, 40%);">+ int stats_res = -1;</span><br><span> </span><br><span> ast_assert(context->output_buffer != NULL);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (!channel) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&context->output_buffer, 0, " %s not valid\n", snapshot->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(channel);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ cpvt = ast_channel_tech_pvt(channel);</span><br><span style="color: hsl(120, 100%, 40%);">+ pvt = cpvt ? cpvt->pvt : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ media = pvt ? pvt->media[SIP_MEDIA_AUDIO] : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!media || !media->rtp) {</span><br><span> ast_str_append(&context->output_buffer, 0, " %s not valid\n", snapshot->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(channel);</span><br><span> ao2_cleanup(channel);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span> codec_in_use[0] = '\0';</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (channel) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_lock(channel);</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_channel_rawreadformat(channel)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_copy_string(codec_in_use, ast_format_get_name(ast_channel_rawreadformat(channel)), sizeof(codec_in_use));</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_unlock(channel);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_channel_rawreadformat(channel)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_string(codec_in_use, ast_format_get_name(ast_channel_rawreadformat(channel)), sizeof(codec_in_use));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ stats_res = ast_rtp_instance_get_stats(media->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(channel);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> print_name = ast_strdupa(snapshot->name);</span><br><span> /* Skip the PJSIP/. We know what channel type it is and we need the space. */</span><br><span> print_name += 6;</span><br><span> </span><br><span> ast_format_duration_hh_mm_ss(ast_tvnow().tv_sec - snapshot->creationtime.tv_sec, print_time, 32);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_rtp_instance_get_stats(media->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (stats_res == -1) {</span><br><span> ast_str_append(&context->output_buffer, 0, "%s direct media\n", snapshot->name);</span><br><span> } else {</span><br><span> ast_str_append(&context->output_buffer, 0,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13044">change 13044</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13044"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Ia918bfa3c8119060633e39b14852e8d983e0417e </div>
<div style="display:none"> Gerrit-Change-Number: 13044 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Salah Ahmed <txrubel@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Salah Ahmed <txrubel@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>