From 76d98d76b4df99e9d0a2cdea080a24dd4fa183b7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 19 May 2008 19:57:27 +0000 Subject: [PATCH] don't leak on switch_ivr_play_file when using phrase or say. Found by Klockwork (www.klocwork.com) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8474 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_ivr_play_say.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index df75f747cd..d820c1de69 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -676,7 +676,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *sessi SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, const char *file, switch_input_args_t *args) { switch_channel_t *channel = switch_core_session_get_channel(session); - int16_t *abuf; + int16_t *abuf = NULL; switch_dtmf_t dtmf = {0}; uint32_t interval = 0, samples = 0, framelen, sample_start = 0; uint32_t ilen = 0; @@ -699,8 +699,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess const char *prebuf; const char *alt = NULL; - switch_zmalloc(abuf, FILE_STARTSAMPLES * sizeof(*abuf)); - switch_channel_pre_answer(channel); prefix = switch_channel_get_variable(channel, "sound_prefix"); @@ -760,12 +758,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess } - if (!prefix) { prefix = SWITCH_GLOBAL_dirs.base_dir; } - if (!strstr(file, SWITCH_URL_SEPARATOR)) { if (!switch_is_file_path(file)) { file = switch_core_session_sprintf(session, "%s%s%s", prefix, SWITCH_PATH_SEPARATOR, file); @@ -809,6 +805,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess asis = 1; } + switch_zmalloc(abuf, FILE_STARTSAMPLES * sizeof(*abuf)); write_frame.data = abuf; write_frame.buflen = FILE_STARTSAMPLES; @@ -1000,7 +997,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess if (done || olen <= 0) { break; } - if (!asis) { if (fh->speed > 2) { @@ -1156,7 +1152,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess end: - free(abuf); + switch_safe_free(abuf); switch_core_session_reset(session, SWITCH_TRUE); return status;