mod_tts_commandline: various memory fixes, corrected indentation

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14933 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Mathieu Parent 2009-09-21 14:11:08 +00:00
parent 25b792f986
commit 22bb9e023b

View File

@ -47,10 +47,10 @@ static struct {
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_command, globals.command); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_command, globals.command);
struct tts_commandline_data { struct tts_commandline_data {
switch_file_handle_t fh;
char *voice_name; char *voice_name;
int rate; int rate;
char *file; char *file;
switch_file_handle_t *fh;
}; };
typedef struct tts_commandline_data tts_commandline_t; typedef struct tts_commandline_data tts_commandline_t;
@ -98,7 +98,7 @@ SWITCH_DECLARE(char *) switch_quote_shell_arg(char *string)
} }
} }
dest_len++; dest_len += 2; /* +2 for the closing quote and the null character */
tmp = (char *) realloc(dest, sizeof(char) * (dest_len)); tmp = (char *) realloc(dest, sizeof(char) * (dest_len));
switch_assert(tmp); switch_assert(tmp);
dest = tmp; dest = tmp;
@ -107,8 +107,8 @@ dest = tmp;
#else #else
dest[n++] = '\''; dest[n++] = '\'';
#endif #endif
dest[n++] = 0;
dest[dest_len] = 0; switch_assert(n == dest_len);
return dest; return dest;
} }
@ -160,11 +160,13 @@ static switch_status_t tts_commandline_speech_open(switch_speech_handle_t *sh, c
info->voice_name = switch_core_strdup(sh->memory_pool, voice_name); info->voice_name = switch_core_strdup(sh->memory_pool, voice_name);
info->rate = rate; info->rate = rate;
/* Construct temporary file name with a new UUID */
switch_uuid_get(&uuid); switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid); switch_uuid_format(uuid_str, &uuid);
switch_snprintf(outfile, sizeof(outfile), "%s%s.tmp.wav", SWITCH_GLOBAL_dirs.temp_dir, uuid_str); switch_snprintf(outfile, sizeof(outfile), "%s%s.tmp.wav", SWITCH_GLOBAL_dirs.temp_dir, uuid_str);
info->file = outfile; info->file = switch_core_strdup(sh->memory_pool, outfile);
info->fh = (switch_file_handle_t *) switch_core_alloc(sh->memory_pool, sizeof(switch_file_handle_t));
sh->private_info = info; sh->private_info = info;
@ -207,7 +209,7 @@ static switch_status_t tts_commandline_speech_feed_tts(switch_speech_handle_t *s
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (switch_core_file_open(&info->fh, if (switch_core_file_open(info->fh,
info->file, info->file,
0, //number_of_channels, 0, //number_of_channels,
0, //samples_per_second, 0, //samples_per_second,
@ -228,7 +230,7 @@ static switch_status_t tts_commandline_speech_read_tts(switch_speech_handle_t *s
size_t my_datalen = *datalen / 2; size_t my_datalen = *datalen / 2;
if (switch_core_file_read(&info->fh, data, &my_datalen) != SWITCH_STATUS_SUCCESS) { if (switch_core_file_read(info->fh, data, &my_datalen) != SWITCH_STATUS_SUCCESS) {
*datalen = my_datalen * 2; *datalen = my_datalen * 2;
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -245,7 +247,7 @@ static void tts_commandline_speech_flush_tts(switch_speech_handle_t *sh)
tts_commandline_t *info = (tts_commandline_t *) sh->private_info; tts_commandline_t *info = (tts_commandline_t *) sh->private_info;
assert(info != NULL); assert(info != NULL);
switch_core_file_close(&info->fh); switch_core_file_close(info->fh);
if (unlink(info->file) != 0) { if (unlink(info->file) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sound file [%s] delete failed\n", info->file); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sound file [%s] delete failed\n", info->file);
} }