From 1c057191002b8fbcabf31d6810fb1a834a148607 Mon Sep 17 00:00:00 2001 From: wmasilva Date: Wed, 24 Jan 2024 19:04:32 +0000 Subject: [PATCH] [Core] softtimer: fix crash in timezones when reloading xml * switch_time: fix segfault null TIMEZONES_LIST.hash when reloading xml * Unbind before destroying TIMEZONES_LIST.hash. Protect TIMEZONES_LIST.hash with a mutex that's allocated in core's global runtime.memory_pool so the mutex does not die on softtimer shutdown. --------- Co-authored-by: Andrey Volk --- src/switch_time.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/switch_time.c b/src/switch_time.c index a56c5e96f1..1ee581453a 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -1384,10 +1384,13 @@ SWITCH_DECLARE(const char *) switch_lookup_timezone(const char *tz_name) return NULL; } + switch_mutex_lock(globals.mutex); if ((value = switch_core_hash_find(TIMEZONES_LIST.hash, tz_name)) == NULL) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timezone '%s' not found!\n", tz_name); } + switch_mutex_unlock(globals.mutex); + return value; } @@ -1522,7 +1525,7 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load) #endif memset(&globals, 0, sizeof(globals)); - switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); + switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, runtime.memory_pool); if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &NODE) != SWITCH_STATUS_SUCCESS)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n"); @@ -1599,18 +1602,21 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown) DeleteCriticalSection(&timer_section); #endif + if (NODE) { + switch_event_unbind(&NODE); + } + + switch_mutex_lock(globals.mutex); if (TIMEZONES_LIST.hash) { switch_core_hash_destroy(&TIMEZONES_LIST.hash); } + switch_mutex_unlock(globals.mutex); + if (TIMEZONES_LIST.pool) { switch_core_destroy_memory_pool(&TIMEZONES_LIST.pool); } - if (NODE) { - switch_event_unbind(&NODE); - } - return SWITCH_STATUS_SUCCESS; }