From 0bdd7007d0dd62b5fa2ca61cfebfb6eeca7436f3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 May 2008 22:12:41 +0000 Subject: [PATCH] don't leak on error conditions in mod_local_stream. Found by Klockwork (www.klocwork.com) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8513 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/formats/mod_local_stream/mod_local_stream.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mod/formats/mod_local_stream/mod_local_stream.c b/src/mod/formats/mod_local_stream/mod_local_stream.c index f966cd73ac..caa84ccd3f 100644 --- a/src/mod/formats/mod_local_stream/mod_local_stream.c +++ b/src/mod/formats/mod_local_stream/mod_local_stream.c @@ -120,10 +120,9 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void if (switch_dir_open(&source->dir_handle, source->location, source->pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't open directory: %s\n", source->location); - return NULL; + goto done; } - //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "open directory: %s\n", source->location); switch_yield(1000000); while(RUNNING) { @@ -181,11 +180,11 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void if (switch_core_timer_init(&timer, source->timer_name, source->interval, source->samples, source->pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't start timer.\n"); - return NULL; + switch_dir_close(source->dir_handle); + source->dir_handle = NULL; + goto done; } - //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Playing [%s] rate: %dhz\n", fname, source->rate); - while (RUNNING) { switch_core_timer_next(&timer); olen = source->samples; @@ -231,6 +230,9 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void source->dir_handle = NULL; } +done: + switch_buffer_destroy(&audio_buffer); + if (fd > -1) { close(fd); }