]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Core] softtimer: fix crash in timezones when reloading xml 2360/head
authorwmasilva <asilva@wirelessmundi.com>
Wed, 24 Jan 2024 19:04:32 +0000 (19:04 +0000)
committerGitHub <noreply@github.com>
Wed, 24 Jan 2024 19:04:32 +0000 (22:04 +0300)
* 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>
src/switch_time.c

index a56c5e96f1fc44895d754ef95827f134a8c41b1b..1ee581453a8d90d49e25e9b1d21ba69ba5f0c092 100644 (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;
 }