Merge pull request #2040 from signalwire/coverity_13042023_mod_translate

[mod_translate] Coverity CID 1301006 (Resource leak)
This commit is contained in:
Andrey Volk 2023-04-17 13:45:56 +03:00 committed by GitHub
commit 12af59e67e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -130,6 +130,7 @@ static void translate_number(char *number, char *profile, char **translated, swi
hi = switch_core_hash_find_rdlock(globals.translate_profiles, (const char *)profile, globals.profile_hash_rwlock);
if (!hi) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "can't find key for profile matching [%s]\n", profile);
return;
}
@ -142,6 +143,7 @@ static void translate_number(char *number, char *profile, char **translated, swi
switch_regex_safe_free(re);
goto end;
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, rule->replace, number, substituted, len, ovector);
@ -153,16 +155,21 @@ static void translate_number(char *number, char *profile, char **translated, swi
} else if (event) {
subbed = switch_event_expand_headers(event, substituted);
}
if (subbed != substituted) {
switch_safe_free(substituted);
}
if (session) {
substituted = switch_core_session_strdup(session, subbed);
} else {
substituted = switch_core_strdup(pool, subbed);
}
if (subbed != substituted) {
switch_safe_free(subbed);
}
switch_safe_free(subbed);
}
switch_regex_safe_free(re);
break;
}
}