[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 <andywolk@gmail.com>
This commit is contained in:
wmasilva 2024-01-24 19:04:32 +00:00 committed by GitHub
parent d148a3e412
commit 1c05719100
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 5 deletions

View File

@ -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;
}