From fae50b4197ffd32e87f09c6986e61f38a15d5e71 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 May 2009 21:31:16 +0000 Subject: [PATCH] prevent buffer destroy race git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13219 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_core_io.c | 3 +++ src/switch_core_session.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/switch_core_io.c b/src/switch_core_io.c index d15512e8b0..b522f08505 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -915,6 +915,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess } else { switch_size_t x; for (x = 0; x < frames; x++) { + if (switch_channel_down(session->channel) || !session->raw_write_buffer) { + goto error; + } if ((session->raw_write_frame.datalen = (uint32_t) switch_buffer_read(session->raw_write_buffer, session->raw_write_frame.data, bytes)) != 0) { int rate; diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 342d0291b7..a70caa7c41 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -879,9 +879,15 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s switch_mutex_unlock(session->resample_mutex); /* clear indications */ switch_core_session_flush_message(session); + /* wipe these, they will be recreated if need be */ - switch_buffer_destroy(&session->raw_read_buffer); + switch_mutex_lock(session->codec_write_mutex); switch_buffer_destroy(&session->raw_write_buffer); + switch_mutex_unlock(session->codec_write_mutex); + + switch_mutex_lock(session->codec_read_mutex); + switch_buffer_destroy(&session->raw_read_buffer); + switch_mutex_unlock(session->codec_read_mutex); if (flush_dtmf) { while ((has = switch_channel_has_dtmf(channel))) {