From 99e26d34487c6cb33847c5635e5ecf416096d2c3 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 6 Apr 2023 11:27:19 +0100 Subject: [PATCH] [mod_dialplan_asterisk] Coverity CID 1214207 (Resource leak) --- .../mod_dialplan_asterisk/mod_dialplan_asterisk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c index 24119f6f8c..652d292e65 100644 --- a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c +++ b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c @@ -142,6 +142,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) if (!caller_profile || zstr(caller_profile->destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n"); + return NULL; } @@ -150,6 +151,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) if (!switch_config_open_file(&cfg, cf)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + return NULL; } @@ -226,12 +228,14 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) } } else { if (pattern && strcasecmp(pattern, field_data)) { + switch_safe_free(field_expanded); continue; } } if (cid) { if (strcasecmp(cid, caller_profile->caller_id_number)) { + switch_safe_free(field_expanded); continue; } } @@ -266,15 +270,19 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) switch_perform_substitution(re, proceed, argument, field_data, substituted, sizeof(substituted), ovector); argument = substituted; } + switch_regex_safe_free(re); if (!extension) { if (zstr(field_data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No extension!\n"); + switch_safe_free(field_expanded); break; } + if ((extension = switch_caller_extension_new(session, field_data, field_data)) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n"); + switch_safe_free(field_expanded); break; } }