From 718d2341f7327feea52c840648e42b33eb9c69dd Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 24 Jul 2019 20:26:32 +0400 Subject: [PATCH] FS-11952: [Core] Fix memory leaks. --- src/mod/applications/mod_callcenter/mod_callcenter.c | 2 ++ src/mod/applications/mod_hash/mod_hash.c | 1 + src/mod/applications/mod_httapi/mod_httapi.c | 1 + .../applications/mod_valet_parking/mod_valet_parking.c | 9 ++++++++- src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c | 1 + .../event_handlers/mod_erlang_event/mod_erlang_event.c | 1 + .../mod_event_multicast/mod_event_multicast.c | 1 + src/mod/event_handlers/mod_rayo/srgs.c | 1 + src/switch_core.c | 6 ++++++ src/switch_msrp.c | 2 ++ src/switch_xml.c | 1 + 11 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_callcenter/mod_callcenter.c b/src/mod/applications/mod_callcenter/mod_callcenter.c index b3f5ca6fee..81fd68cf72 100644 --- a/src/mod/applications/mod_callcenter/mod_callcenter.c +++ b/src/mod/applications/mod_callcenter/mod_callcenter.c @@ -4274,6 +4274,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_callcenter_shutdown) queue = NULL; } + switch_core_hash_destroy(&globals.queue_hash); + switch_safe_free(globals.odbc_dsn); switch_safe_free(globals.dbname); switch_safe_free(globals.cc_instance_id); diff --git a/src/mod/applications/mod_hash/mod_hash.c b/src/mod/applications/mod_hash/mod_hash.c index ed86ab34fb..1e8ebc56f5 100644 --- a/src/mod/applications/mod_hash/mod_hash.c +++ b/src/mod/applications/mod_hash/mod_hash.c @@ -788,6 +788,7 @@ void limit_remote_destroy(limit_remote_t **r) switch_thread_rwlock_destroy((*r)->rwlock); switch_core_destroy_memory_pool(&((*r)->pool)); + switch_core_hash_destroy(&(*r)->index); *r = NULL; } } diff --git a/src/mod/applications/mod_httapi/mod_httapi.c b/src/mod/applications/mod_httapi/mod_httapi.c index 3e28bd16ef..fed78535e2 100644 --- a/src/mod/applications/mod_httapi/mod_httapi.c +++ b/src/mod/applications/mod_httapi/mod_httapi.c @@ -3242,6 +3242,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_httapi_shutdown) switch_core_hash_destroy(&globals.profile_hash); switch_core_hash_destroy(&globals.parse_hash); + switch_core_hash_destroy(&globals.request_hash); while (globals.hash_root) { ptr = globals.hash_root; diff --git a/src/mod/applications/mod_valet_parking/mod_valet_parking.c b/src/mod/applications/mod_valet_parking/mod_valet_parking.c index 4bd9ac6e3d..b938a2953d 100644 --- a/src/mod/applications/mod_valet_parking/mod_valet_parking.c +++ b/src/mod/applications/mod_valet_parking/mod_valet_parking.c @@ -37,11 +37,12 @@ /* Prototypes */ SWITCH_MODULE_LOAD_FUNCTION(mod_valet_parking_load); +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_valet_parking_shutdown); /* SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime) * Defines a switch_loadable_module_function_table_t and a static const char[] modname */ -SWITCH_MODULE_DEFINITION(mod_valet_parking, mod_valet_parking_load, NULL, NULL); +SWITCH_MODULE_DEFINITION(mod_valet_parking, mod_valet_parking_load, mod_valet_parking_shutdown, NULL); typedef struct { char ext[256]; @@ -930,6 +931,12 @@ static void pres_event_handler(switch_event_t *event) switch_safe_free(dup_lot_name); } +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_valet_parking_shutdown) +{ + switch_core_hash_destroy(&globals.hash); + return SWITCH_STATUS_SUCCESS; +} + /* Macro expands to: switch_status_t mod_valet_parking_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */ SWITCH_MODULE_LOAD_FUNCTION(mod_valet_parking_load) { diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index 885c35c64c..402a20224d 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -555,6 +555,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_pg_csv_shutdown) switch_event_unbind_callback(event_handler); switch_core_remove_state_handler(&state_handlers); + switch_core_hash_destroy(&globals.fd_hash); return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c index 51839141e9..ee10130a0c 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c @@ -1399,6 +1399,7 @@ void destroy_listener(listener_t * listener) switch_mutex_unlock(listener->sock_mutex); switch_core_hash_destroy(&listener->event_hash); + switch_core_hash_destroy(&listener->sessions); /* remove any bindings for this connection */ remove_binding(listener, NULL); diff --git a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c index f591855a3e..3a5c011996 100644 --- a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c +++ b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c @@ -502,6 +502,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown) switch_event_free_subclass(MULTICAST_PEERDOWN); switch_core_hash_destroy(&globals.event_hash); + switch_core_hash_destroy(&globals.peer_hash); switch_safe_free(globals.address); switch_safe_free(globals.bindings); diff --git a/src/mod/event_handlers/mod_rayo/srgs.c b/src/mod/event_handlers/mod_rayo/srgs.c index 5da3bce693..6a3111704f 100644 --- a/src/mod/event_handlers/mod_rayo/srgs.c +++ b/src/mod/event_handlers/mod_rayo/srgs.c @@ -852,6 +852,7 @@ static void srgs_grammar_destroy(struct srgs_grammar *grammar) switch_file_remove(grammar->jsgf_file_name, pool); } switch_core_destroy_memory_pool(&pool); + switch_core_hash_destroy(&grammar->rules); } /** diff --git a/src/switch_core.c b/src/switch_core.c index da17218974..56ca7e81c7 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -2985,6 +2985,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void) switch_loadable_module_shutdown(); + switch_curl_destroy(); + switch_ssl_destroy_ssl_locks(); switch_scheduler_task_thread_stop(); @@ -3032,6 +3034,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void) switch_safe_free(SWITCH_GLOBAL_dirs.temp_dir); switch_safe_free(SWITCH_GLOBAL_dirs.data_dir); switch_safe_free(SWITCH_GLOBAL_dirs.localstate_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.certs_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.lib_dir); + + switch_safe_free(SWITCH_GLOBAL_filenames.conf_name); switch_event_destroy(&runtime.global_vars); switch_core_hash_destroy(&runtime.ptimes); diff --git a/src/switch_msrp.c b/src/switch_msrp.c index e787509ba6..6cf2974d3e 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -351,6 +351,8 @@ SWITCH_DECLARE(switch_status_t) switch_msrp_destroy() msrp_deinit_ssl(); + switch_safe_free(globals.ip); + return st; } diff --git a/src/switch_xml.c b/src/switch_xml.c index 60004f29d6..f2e43f6318 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -2451,6 +2451,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_destroy(void) switch_xml_clear_user_cache(NULL, NULL, NULL); switch_core_hash_destroy(&CACHE_HASH); + switch_core_hash_destroy(&CACHE_EXPIRES_HASH); return status; }