diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 7adcad1ec9..a6a557f800 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -30320,22 +30320,22 @@ static enum ast_rtp_glue_result sip_get_rtp_peer(struct ast_channel *chan, struc return AST_RTP_GLUE_RESULT_FORBID; } - if (!(opp_chan = ast_bridged_channel(chan))) { - return AST_RTP_GLUE_RESULT_FORBID; - } else if (((opp_chan->tech != &sip_tech) && (opp_chan->tech != &sip_tech_info)) || - (!(opp = opp_chan->tech_pvt))) { + if ((opp_chan = ast_bridged_channel(chan)) && (((opp_chan->tech != &sip_tech) && (opp_chan->tech != &sip_tech_info)) || + (!(opp = opp_chan->tech_pvt)))) { return AST_RTP_GLUE_RESULT_FORBID; } sip_pvt_lock(p); - while (sip_pvt_trylock(opp)) { + while (opp && sip_pvt_trylock(opp)) { sip_pvt_unlock(p); usleep(1); sip_pvt_lock(p); } if (!(p->rtp)) { - sip_pvt_unlock(opp); + if (opp) { + sip_pvt_unlock(opp); + } sip_pvt_unlock(p); return AST_RTP_GLUE_RESULT_FORBID; } @@ -30345,7 +30345,7 @@ static enum ast_rtp_glue_result sip_get_rtp_peer(struct ast_channel *chan, struc if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) { res = AST_RTP_GLUE_RESULT_REMOTE; - if (!apply_directmedia_ha(p, opp, "audio")) { + if (opp && !apply_directmedia_ha(p, opp, "audio")) { res = AST_RTP_GLUE_RESULT_FORBID; } } else if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA_NAT)) { @@ -30354,7 +30354,9 @@ static enum ast_rtp_glue_result sip_get_rtp_peer(struct ast_channel *chan, struc res = AST_RTP_GLUE_RESULT_FORBID; } - sip_pvt_unlock(opp); + if (opp) { + sip_pvt_unlock(opp); + } if (p->srtp) { res = AST_RTP_GLUE_RESULT_FORBID; @@ -30376,22 +30378,22 @@ static enum ast_rtp_glue_result sip_get_vrtp_peer(struct ast_channel *chan, stru return AST_RTP_GLUE_RESULT_FORBID; } - if (!(opp_chan = ast_bridged_channel(chan))) { - return AST_RTP_GLUE_RESULT_FORBID; - } else if (((opp_chan->tech != &sip_tech) && (opp_chan->tech != &sip_tech_info)) || - (!(opp = opp_chan->tech_pvt))) { + if ((opp_chan = ast_bridged_channel(chan)) && (((opp_chan->tech != &sip_tech) && (opp_chan->tech != &sip_tech_info)) || + (!(opp = opp_chan->tech_pvt)))) { return AST_RTP_GLUE_RESULT_FORBID; } sip_pvt_lock(p); - while (sip_pvt_trylock(opp)) { + while (opp && sip_pvt_trylock(opp)) { sip_pvt_unlock(p); usleep(1); sip_pvt_lock(p); } if (!(p->vrtp)) { - sip_pvt_unlock(opp); + if (opp) { + sip_pvt_unlock(opp); + } sip_pvt_unlock(p); return AST_RTP_GLUE_RESULT_FORBID; } @@ -30401,12 +30403,14 @@ static enum ast_rtp_glue_result sip_get_vrtp_peer(struct ast_channel *chan, stru if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) { res = AST_RTP_GLUE_RESULT_REMOTE; - if (!apply_directmedia_ha(p, opp, "video")) { + if (opp && !apply_directmedia_ha(p, opp, "video")) { res = AST_RTP_GLUE_RESULT_FORBID; } } - sip_pvt_unlock(opp); + if (opp) { + sip_pvt_unlock(opp); + } sip_pvt_unlock(p); return res; @@ -30423,22 +30427,22 @@ static enum ast_rtp_glue_result sip_get_trtp_peer(struct ast_channel *chan, stru return AST_RTP_GLUE_RESULT_FORBID; } - if (!(opp_chan = ast_bridged_channel(chan))) { - return AST_RTP_GLUE_RESULT_FORBID; - } else if (((opp_chan->tech != &sip_tech) && (opp_chan->tech != &sip_tech_info)) || - (!(opp = opp_chan->tech_pvt))) { + if ((opp_chan = ast_bridged_channel(chan)) && (((opp_chan->tech != &sip_tech) && (opp_chan->tech != &sip_tech_info)) || + (!(opp = opp_chan->tech_pvt)))) { return AST_RTP_GLUE_RESULT_FORBID; } sip_pvt_lock(p); - while (sip_pvt_trylock(opp)) { + while (opp && sip_pvt_trylock(opp)) { sip_pvt_unlock(p); usleep(1); sip_pvt_lock(p); } if (!(p->trtp)) { - sip_pvt_unlock(opp); + if (opp) { + sip_pvt_unlock(opp); + } sip_pvt_unlock(p); return AST_RTP_GLUE_RESULT_FORBID; } @@ -30448,12 +30452,14 @@ static enum ast_rtp_glue_result sip_get_trtp_peer(struct ast_channel *chan, stru if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) { res = AST_RTP_GLUE_RESULT_REMOTE; - if (!apply_directmedia_ha(p, opp, "text")) { + if (opp && !apply_directmedia_ha(p, opp, "text")) { res = AST_RTP_GLUE_RESULT_FORBID; } } - sip_pvt_unlock(opp); + if (opp) { + sip_pvt_unlock(opp); + } sip_pvt_unlock(p); return res;