From cd5d72ac744208ae63b0b81d18410f30eb8224da Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 31 Oct 2019 21:39:50 +0400 Subject: [PATCH] [Core] Database interface: fix potential crash in switch_cache_db_database_interface_flush_handles, code cleanup. --- src/switch_core_sqldb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index b2ba795115..7f5c2aff52 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -153,6 +153,8 @@ SWITCH_DECLARE(void) switch_cache_db_database_interface_flush_handles(switch_dat switch_mutex_lock(sql_manager.dbh_mutex); +top: + for (dbh_ptr = sql_manager.handle_pool; dbh_ptr; dbh_ptr = dbh_ptr->next) { if (switch_mutex_trylock(dbh_ptr->mutex) == SWITCH_STATUS_SUCCESS) { if (dbh_ptr->type != SCDB_TYPE_DATABASE_INTERFACE) { @@ -170,6 +172,7 @@ SWITCH_DECLARE(void) switch_cache_db_database_interface_flush_handles(switch_dat del_handle(dbh_ptr); switch_mutex_unlock(dbh_ptr->mutex); destroy_handle(&dbh_ptr); + goto top; } } @@ -303,7 +306,7 @@ static void sql_close(time_t prune) del_handle(dbh); switch_mutex_unlock(dbh->mutex); - switch_core_destroy_memory_pool(&dbh->pool); + destroy_handle(&dbh); goto top; } else { @@ -432,7 +435,7 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle_dsn_ex(switch_cac const char *file, const char *func, int line) { switch_cache_db_connection_options_t connection_options = { {0} }; - switch_cache_db_handle_type_t type; + switch_cache_db_handle_type_t type = SCDB_TYPE_CORE_DB; switch_database_interface_t *database_interface = NULL; char tmp[256] = ""; char *p;