From 79069c66d1bff4b0b0c639453bdeaf084e7c8633 Mon Sep 17 00:00:00 2001 From: William King Date: Tue, 15 Jan 2013 13:22:28 -0800 Subject: [PATCH] FS-3882, FS-3546, FS-3712, FS-3970: --resolve Fixes the segfault in mod_rtmp where the channel was destroyed, but the endpoint still tried to send or receive data from the session. --- src/mod/endpoints/mod_rtmp/mod_rtmp.c | 3 +++ src/mod/endpoints/mod_rtmp/rtmp.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/mod/endpoints/mod_rtmp/mod_rtmp.c b/src/mod/endpoints/mod_rtmp/mod_rtmp.c index 844b1483d0..164491a70b 100644 --- a/src/mod/endpoints/mod_rtmp/mod_rtmp.c +++ b/src/mod/endpoints/mod_rtmp/mod_rtmp.c @@ -250,6 +250,7 @@ switch_status_t rtmp_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); + switch_thread_rwlock_wrlock(tech_pvt->rtmp_session->rwlock); switch_clear_flag_locked(tech_pvt, TFLAG_IO); //switch_thread_cond_signal(tech_pvt->cond); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); @@ -286,6 +287,8 @@ switch_status_t rtmp_on_hangup(switch_core_session_t *session) } #endif + switch_thread_rwlock_unlock(tech_pvt->rtmp_session->rwlock); + return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_rtmp/rtmp.c b/src/mod/endpoints/mod_rtmp/rtmp.c index d334feea4b..1c3bee44bc 100644 --- a/src/mod/endpoints/mod_rtmp/rtmp.c +++ b/src/mod/endpoints/mod_rtmp/rtmp.c @@ -906,10 +906,12 @@ switch_status_t rtmp_handle_data(rtmp_session_t *rsession) rtmp_handle_invoke(rsession, rsession->amfnumber); break; case RTMP_TYPE_AUDIO: /* Audio data */ + switch_thread_rwlock_wrlock(rsession->rwlock); if (rsession->tech_pvt) { uint16_t len = state->origlen; if (!rsession->tech_pvt->readbuf) { + switch_thread_rwlock_unlock(rsession->rwlock); return SWITCH_STATUS_FALSE; } @@ -936,6 +938,8 @@ switch_status_t rtmp_handle_data(rtmp_session_t *rsession) } switch_mutex_unlock(rsession->tech_pvt->readbuf_mutex); } + switch_thread_rwlock_unlock(rsession->rwlock); + break; case RTMP_TYPE_VIDEO: /* Video data */ case RTMP_TYPE_METADATA: /* Metadata */