]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Fix memory leaks in mod_tts_commandline
authorTravis Cross <tc@traviscross.com>
Sun, 26 May 2013 01:03:08 +0000 (01:03 +0000)
committerTravis Cross <tc@traviscross.com>
Sun, 26 May 2013 01:08:10 +0000 (01:08 +0000)
We were using both switch_util_quote_shell_arg and
switch_string_replace without freeing the results even though both
functions malloc.

src/mod/asr_tts/mod_tts_commandline/mod_tts_commandline.c

index 80be1d9686876dde0d86b94462d18edb852def3b..6020ca4290a865e460f0a69cc292c8b09c64acbc 100644 (file)
@@ -130,7 +130,8 @@ static switch_status_t tts_commandline_speech_close(switch_speech_handle_t *sh,
 
 static switch_status_t tts_commandline_speech_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
 {
-       char *message, *tmp, *rate;
+       switch_status_t ret=SWITCH_STATUS_SUCCESS;
+       char *message, *tmp, *mtmp, *rate;
        tts_commandline_t *info = (tts_commandline_t *) sh->private_info;
 
        assert(info != NULL);
@@ -140,37 +141,41 @@ static switch_status_t tts_commandline_speech_feed_tts(switch_speech_handle_t *s
                unlink(info->file);
        }
 
-       message = switch_core_strdup(sh->memory_pool, globals.command);
-
        tmp = switch_util_quote_shell_arg(text);
-       message = switch_string_replace(message, "${text}", tmp);
+       message = switch_string_replace(globals.command, "${text}", tmp);
+       switch_safe_free(tmp); mtmp=message;
 
        tmp = switch_util_quote_shell_arg(info->voice_name);
-       message = switch_string_replace(message, "${voice}", tmp);
+       message = switch_string_replace(mtmp, "${voice}", tmp);
+       switch_safe_free(tmp); switch_safe_free(mtmp); mtmp=message;
 
        rate = switch_core_sprintf(sh->memory_pool, "%d", info->rate);
-       message = switch_string_replace(message, "${rate}", rate);
+       message = switch_string_replace(mtmp, "${rate}", rate);
+       switch_safe_free(mtmp); mtmp=message;
 
        tmp = switch_util_quote_shell_arg(info->file);
-       message = switch_string_replace(message, "${file}", tmp);
+       message = switch_string_replace(mtmp, "${file}", tmp);
+       switch_safe_free(tmp); switch_safe_free(mtmp); mtmp=message;
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing: %s\n", message);
 
        if (switch_system(message, SWITCH_TRUE) < 0) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute command: %s\n", message);
-               return SWITCH_STATUS_FALSE;
+               ret = SWITCH_STATUS_FALSE; goto done;
        }
 
        if (switch_core_file_open(info->fh, info->file, 0,      //number_of_channels,
                                                          info->rate,   //samples_per_second,
                                                          SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file: %s\n", info->file);
-               return SWITCH_STATUS_FALSE;
+               ret = SWITCH_STATUS_FALSE; goto done;
        }
 
        sh->private_info = info;
 
-       return SWITCH_STATUS_SUCCESS;
+ done:
+       switch_safe_free(mtmp);
+       return ret;
 }
 
 static switch_status_t tts_commandline_speech_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, switch_speech_flag_t *flags)