]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-12010: [mod_sofia, mod_valet_parking, mod_enum] Fix memory leaks on FreeSWITCH...
authorAndrey Volk <andywolk@gmail.com>
Sun, 18 Aug 2019 13:23:03 +0000 (17:23 +0400)
committerAndrey Volk <andywolk@gmail.com>
Mon, 19 Aug 2019 19:14:24 +0000 (23:14 +0400)
src/mod/applications/mod_enum/mod_enum.c
src/mod/applications/mod_valet_parking/mod_valet_parking.c
src/mod/endpoints/mod_sofia/mod_sofia.c

index 3e458dd1297676a583df03c3de6cedfeaf26123e..f6ca99abce902d8b3b8f7a5dbe669f8298013f7f 100644 (file)
@@ -75,6 +75,9 @@ static struct {
        int retries;
        int random;
        char *nameserver[ENUM_MAXNAMESERVERS];
+#ifdef _MSC_VER
+       char *nameserver_buf;
+#endif
 } globals;
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_root, globals.root);
@@ -164,7 +167,6 @@ static switch_status_t load_config(void)
        if (!globals.nameserver[0]) {
                HKEY hKey;
                DWORD data_sz;
-               char* buf;
                RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                        "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
                        0, KEY_QUERY_VALUE, &hKey);
@@ -172,15 +174,15 @@ static switch_status_t load_config(void)
                if (hKey) {
                        RegQueryValueEx(hKey, "DhcpNameServer", NULL, NULL, NULL, &data_sz);
                        if (data_sz) {
-                               buf = (char*)malloc(data_sz + 1);
+                               globals.nameserver_buf = (char*)malloc(data_sz + 1);
 
-                               RegQueryValueEx(hKey, "DhcpNameServer", NULL, NULL, (LPBYTE)buf, &data_sz);
+                               RegQueryValueEx(hKey, "DhcpNameServer", NULL, NULL, (LPBYTE)globals.nameserver_buf, &data_sz);
 
-                               if(buf[data_sz - 1] != 0) {
-                                       buf[data_sz] = 0;
+                               if(globals.nameserver_buf[data_sz - 1] != 0) {
+                                       globals.nameserver_buf[data_sz] = 0;
                                }
-                               switch_replace_char(buf, ' ', 0, SWITCH_FALSE); /* only use the first entry ex "192.168.1.1 192.168.1.2" */
-                               globals.nameserver[0] = buf;
+                               switch_replace_char(globals.nameserver_buf, ' ', 0, SWITCH_FALSE); /* only use the first entry ex "192.168.1.1 192.168.1.2" */
+                               globals.nameserver[0] = globals.nameserver_buf;
                        }
                        
                        RegCloseKey(hKey);
@@ -924,6 +926,9 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_enum_shutdown)
 
        switch_safe_free(globals.root);
        switch_safe_free(globals.isn_root);
+#ifdef _MSC_VER
+       switch_safe_free(globals.nameserver_buf);
+#endif
 
        return SWITCH_STATUS_UNLOAD;
 }
index b938a2953dd5daf17fc22f847d6768efa4a44408..0c95c16265236d8616587d3fb4ef6a375415fc3d 100644 (file)
@@ -933,6 +933,7 @@ static void pres_event_handler(switch_event_t *event)
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_valet_parking_shutdown)
 {
+       switch_event_unbind_callback(pres_event_handler);
        switch_core_hash_destroy(&globals.hash);
        return SWITCH_STATUS_SUCCESS;
 }
index cd6b1c8f8850a1c91eb485bdc7abee881025cb00..c35f37d4fefbfb64327f64d817602b03718bfca4 100644 (file)
@@ -6473,6 +6473,12 @@ void mod_sofia_shutdown_cleanup() {
 
        su_deinit();
 
+       /* 
+               Release the clone of the default SIP parser 
+               created by `sip_update_default_mclass(sip_extend_mclass(NULL))` call with NULL argument
+       */
+       free(sip_default_mclass());
+
        switch_mutex_lock(mod_sofia_globals.hash_mutex);
        switch_core_hash_destroy(&mod_sofia_globals.profile_hash);
        switch_core_hash_destroy(&mod_sofia_globals.gateway_hash);