]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[core] Remove 255 byte limit to core ASR param stored in module name
authorChris Rienzo <chris@signalwire.com>
Wed, 20 May 2020 02:20:22 +0000 (02:20 +0000)
committerAndrey Volk <andywolk@gmail.com>
Sat, 23 Oct 2021 18:59:58 +0000 (21:59 +0300)
src/switch_core_asr.c

index 6f633020429218fc1f013d17c92fccb2584f1d2e..dd0df4302e23530418aaf0f08f1a5a14ab6dcde3 100644 (file)
@@ -42,14 +42,22 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah,
                                                                                                         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;
                }
        }
 
@@ -57,23 +65,20 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah,
 
        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);
@@ -83,6 +88,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah,
        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);
        }