From 19dc1ab0f207d20a0934cd0c15b1e7757070be25 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 16 Sep 2010 20:08:30 +0400 Subject: [PATCH] fix crashes on FSH323Connection calls in on_hangup routine in different threads. --- src/mod/endpoints/mod_h323/changes.txt | 1 + src/mod/endpoints/mod_h323/mod_h323.cpp | 24 +++++++++++++++++++----- src/mod/endpoints/mod_h323/mod_h323.h | 7 ++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/mod/endpoints/mod_h323/changes.txt b/src/mod/endpoints/mod_h323/changes.txt index ff47780118..19aca46dc8 100644 --- a/src/mod/endpoints/mod_h323/changes.txt +++ b/src/mod/endpoints/mod_h323/changes.txt @@ -1,3 +1,4 @@ +fix crashes on FSH323Connection calls in on_hangup routine in different threads. move PTrace level set to FSH323EndPoint::Initialise partially apply patch from from Peter Olsson, Remove UnLock() when TryLock() failed and DEBUG_RTP_PACKETS directive. apply changes from mod_h323-patch.diff by Peter Olsson. diff --git a/src/mod/endpoints/mod_h323/mod_h323.cpp b/src/mod/endpoints/mod_h323/mod_h323.cpp index aeee422ca5..142506dd92 100644 --- a/src/mod/endpoints/mod_h323/mod_h323.cpp +++ b/src/mod/endpoints/mod_h323/mod_h323.cpp @@ -24,7 +24,7 @@ * * mod_h323.cpp -- H323 endpoint * - * Version 0.0.55 + * Version 0.0.56 */ //#define DEBUG_RTP_PACKETS @@ -747,6 +747,17 @@ FSH323Connection::~FSH323Connection() // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"------------->h323_mutex_unlock\n"); } +void FSH323Connection::AttachSignalChannel(const PString & token, + H323Transport * channel, + PBoolean answeringCall) +{ + h323_private_t *tech_pvt = (h323_private_t *) switch_core_session_get_private(m_fsSession); + tech_pvt->token = strdup((const char *)token); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"---------->token = %s [%p]\n",(const char *)token,this); + H323Connection::AttachSignalChannel(token,channel,answeringCall); +} + + void FSH323Connection::OnSetLocalCapabilities() { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"======>FSH323Connection::OnSetLocalCapabilities() [%p]\n",this); @@ -2321,8 +2332,9 @@ static switch_status_t on_hangup(switch_core_session_t *session) switch_channel_t *channel = switch_core_session_get_channel(session); h323_private_t *tech_pvt = (h323_private_t *) switch_core_session_get_private(session); FSH323Connection *me = tech_pvt->me; + FSH323EndPoint & ep = h323_process->GetH323EndPoint(); tech_pvt->me = NULL; - + if (me) { if (me->m_rtp_resetting == 1) { switch_core_session_unlock_codec_read(session); @@ -2340,12 +2352,12 @@ static switch_status_t on_hangup(switch_core_session_t *session) me->CloseAllLogicalChannels(false); me->Unlock(); } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"----->%s\n",(const char *)(me->GetCallToken())); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"----->%s\n",(const char *)(tech_pvt->token)); Q931::CauseValues cause = (Q931::CauseValues)switch_channel_get_cause_q850(channel); int trylock = me->TryLock(); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"-----> () = %d\n",trylock); if (trylock == 1) { - const PString currentToken(me->GetCallToken()); + const PString currentToken(tech_pvt->token); FSH323Connection *connection = (FSH323Connection *)me->GetEndPoint()->FindConnectionWithLock(currentToken); if (connection) { connection->Unlock(); @@ -2356,8 +2368,10 @@ static switch_status_t on_hangup(switch_core_session_t *session) } else if (trylock == -1) { /* Failed to lock - just go on */ } + const PString currentToken(tech_pvt->token); me->SetQ931Cause(cause); - me->ClearCallSynchronous(NULL, H323TranslateToCallEndReason(cause, UINT_MAX)); +// me->ClearCallSynchronous(NULL, H323TranslateToCallEndReason(cause, UINT_MAX)); + ep.ClearCall(currentToken, H323TranslateToCallEndReason(cause, UINT_MAX)); // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"------------->h323_mutex_lock\n"); // switch_mutex_lock(tech_pvt->h323_mutex); } diff --git a/src/mod/endpoints/mod_h323/mod_h323.h b/src/mod/endpoints/mod_h323/mod_h323.h index 087540c509..8127206126 100644 --- a/src/mod/endpoints/mod_h323/mod_h323.h +++ b/src/mod/endpoints/mod_h323/mod_h323.h @@ -184,6 +184,7 @@ typedef struct { switch_mutex_t *h323_io_mutex; FSH323Connection *me; + char *token; } h323_private_t; #define DECLARE_CALLBACK0(name) \ @@ -306,7 +307,11 @@ class FSH323Connection:public H323Connection { unsigned callReference, switch_caller_profile_t *outbound_profile, switch_core_session_t *fsSession, switch_channel_t *fsChannel); ~FSH323Connection(); - + virtual void AttachSignalChannel( + const PString & token, + H323Transport * channel, + PBoolean answeringCall + ); virtual H323Channel *CreateRealTimeLogicalChannel(const H323Capability & capability, H323Channel::Directions dir, unsigned sessionID, const H245_H2250LogicalChannelParameters * param, RTP_QOS * rtpqos = NULL);