const char *codec, int rate, const char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool)
{
switch_status_t status;
- char buf[256] = "";
+ char *module_name_dup = NULL;
char *param = NULL;
+ int free_pool = 0;
+
+ if (!pool) {
+ if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) {
+ return status;
+ }
+ free_pool = 1;
+ }
if (strchr(module_name, ':')) {
- switch_set_string(buf, module_name);
- if ((param = strchr(buf, ':'))) {
+ module_name_dup = switch_core_strdup(pool, module_name);
+ if ((param = strchr(module_name_dup, ':'))) {
*param++ = '\0';
- module_name = buf;
+ module_name = module_name_dup;
}
}
if ((ah->asr_interface = switch_loadable_module_get_asr_interface(module_name)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ASR module [%s]!\n", module_name);
+ if (free_pool) {
+ switch_core_destroy_memory_pool(&pool);
+ }
return SWITCH_STATUS_GENERR;
}
ah->flags = *flags;
- if (pool) {
- ah->memory_pool = pool;
- } else {
- if ((status = switch_core_new_memory_pool(&ah->memory_pool)) != SWITCH_STATUS_SUCCESS) {
- UNPROTECT_INTERFACE(ah->asr_interface);
- return status;
- }
+ ah->memory_pool = pool;
+ if (free_pool) {
switch_set_flag(ah, SWITCH_ASR_FLAG_FREE_POOL);
}
-
if (param) {
- ah->param = switch_core_strdup(ah->memory_pool, param);
+ ah->param = param;
}
ah->rate = rate;
ah->name = switch_core_strdup(ah->memory_pool, module_name);
status = ah->asr_interface->asr_open(ah, codec, rate, dest, flags);
if (status != SWITCH_STATUS_SUCCESS) {
+ if (switch_test_flag(ah, SWITCH_ASR_FLAG_FREE_POOL)) {
+ switch_core_destroy_memory_pool(&ah->memory_pool);
+ }
UNPROTECT_INTERFACE(ah->asr_interface);
}