From 77fb5b4bc75a9db7def602be6f25628097709c39 Mon Sep 17 00:00:00 2001 From: Sebastian Beckmann Date: Thu, 18 Sep 2025 23:40:53 +0200 Subject: [PATCH] libobs: Disallow overwriting the crash handler Setting a new crash handler overwrites the existing one. This is not desirable. --- docs/sphinx/reference-libobs-util-base.rst | 1 + libobs/util/base.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/docs/sphinx/reference-libobs-util-base.rst b/docs/sphinx/reference-libobs-util-base.rst index 8485fca8d..ff6a59327 100644 --- a/docs/sphinx/reference-libobs-util-base.rst +++ b/docs/sphinx/reference-libobs-util-base.rst @@ -55,6 +55,7 @@ Logging Functions .. function:: void base_set_crash_handler(void (*handler)(const char *, va_list, void *), void *param) Sets the current crash handler. + This may only be set once. --------------------- diff --git a/libobs/util/base.c b/libobs/util/base.c index 4e91dcb1d..de992a096 100644 --- a/libobs/util/base.c +++ b/libobs/util/base.c @@ -19,6 +19,7 @@ #include "c99defs.h" #include "base.h" +#include "threading.h" static int crashing = 0; static void *log_param = NULL; @@ -83,6 +84,13 @@ void base_set_log_handler(log_handler_t handler, void *param) void base_set_crash_handler(void (*handler)(const char *, va_list, void *), void *param) { + static bool non_default_handler_set = false; + + if (os_atomic_exchange_bool(&non_default_handler_set, true)) { + blog(LOG_WARNING, "Tried to set a crash handler when one already exists."); + return; + } + crash_param = param; crash_handler = handler; }