]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11903: Fix errors reported by PVS-Studio Static Code Analyzer for switch_ivr_menu.c
authorAndrey Volk <andywolk@gmail.com>
Fri, 12 Jul 2019 16:42:44 +0000 (20:42 +0400)
committerAndrey Volk <andywolk@gmail.com>
Mon, 15 Jul 2019 19:42:06 +0000 (23:42 +0400)
src/switch_ivr_menu.c

index ec0723031639774161563180f880b5a2d7a3e3ed..3d55e4dac090cb4730ba7c7ec74a5406821501fc 100644 (file)
@@ -143,9 +143,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t ** new_me
        if (!(menu = switch_core_alloc(pool, sizeof(*menu)))) {
                if (newpool) {
                        switch_core_destroy_memory_pool(&pool);
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-                       return SWITCH_STATUS_MEMERR;
                }
+
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+               return SWITCH_STATUS_MEMERR;
        }
 
        menu->pool = pool;
@@ -458,12 +459,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s
        switch_channel_t *channel;
        switch_status_t status = SWITCH_STATUS_SUCCESS;
 
+       switch_assert(stack);
+
        if (++stack->stack_count > 12) {
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Too many levels of recursion.\n");
                switch_goto_status(SWITCH_STATUS_FALSE, end);
        }
 
-       if (!session || !stack || zstr(name)) {
+       if (!session || zstr(name)) {
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid menu context\n");
                switch_goto_status(SWITCH_STATUS_FALSE, end);
        }
@@ -897,6 +900,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_
                                                                          atoi(timeout),
                                                                          strlen(max_failures) ? atoi(max_failures) : 0, strlen(max_timeouts) ? atoi(max_timeouts) : 0, xml_menu_ctx->pool);
 
+               switch_assert(menu);
 
                if (!zstr(exec_on_max_fail)) {
                        menu->exec_on_max_fail = switch_core_strdup(menu->pool, exec_on_max_fail);
@@ -927,7 +931,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_
                        }
                }
 
-               if (status == SWITCH_STATUS_SUCCESS && menu != NULL) {
+               if (status == SWITCH_STATUS_SUCCESS) {
                        switch_xml_t xml_kvp;
 
                        /* build menu entries */