From 3b63db2bde9002201f6dd44ceb3d47e972588d24 Mon Sep 17 00:00:00 2001 From: TheRealAlexV Date: Sat, 29 Aug 2026 22:03:10 -0400 Subject: [PATCH] Fix crash in SendWebsocketVendorEvent during OBS shutdown Guard the vendor event emission with obs_get_module("obs-websocket"). During obs_shutdown() modules are unloaded one-by-one; obs-websocket is unloaded before advanced-scene-switcher, so the proc handler pointer (_ph) cached in obs-websocket-api.h is already stale when FreeSceneSwitcher() runs its stop steps. proc_handler_call() then dereferences freed memory (use-after-free in pthread_mutex_unlock). The existing OBSIsShuttingDown() guard does not catch this path: the forced-exit that follows a "Source Cleanup Error" (scene collection switch) never fires the SCRIPTING_SHUTDOWN frontend event, so the plugin's obsIsShuttingDown flag is not set. obs_get_module() returns NULL once the module is unloaded, which is the reliable signal that obs-websocket's proc handler is gone. Refs: #1404 --- lib/utils/websocket-api.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/utils/websocket-api.cpp b/lib/utils/websocket-api.cpp index 9e33ec52..c3e53c86 100644 --- a/lib/utils/websocket-api.cpp +++ b/lib/utils/websocket-api.cpp @@ -127,9 +127,10 @@ void RegisterWebsocketRequest( void SendWebsocketVendorEvent(const std::string &eventName, obs_data_t *data) { - if (OBSIsShuttingDown()) { + if (OBSIsShuttingDown() || !obs_get_module("obs-websocket")) { return; } + obs_websocket_vendor_emit_event(vendor, eventName.c_str(), data); }