]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_translate] Coverity CID 1301006 (Resource leak) 2040/head
authorJakub Karolczyk <jakub.karolczyk@signalwire.com>
Thu, 13 Apr 2023 13:54:50 +0000 (14:54 +0100)
committerJakub Karolczyk <jakub.karolczyk@signalwire.com>
Sun, 16 Apr 2023 13:22:09 +0000 (14:22 +0100)
src/mod/applications/mod_translate/mod_translate.c

index efbcd3f14ba75a27c713abc7db58ea181f640b34..34b1ad54fc9f9d973c64d884c69a8fed6b77b91b 100644 (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;
                }
        }