From 62617a35de28df2a2ddc1a1daa6f55869c781426 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 10 Oct 2026 15:43:20 +0800 Subject: [PATCH] Common (Debug): fixes possible errno lost --- src/common/impl/debug.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/impl/debug.c b/src/common/impl/debug.c index 86e76383f..b72c3dea3 100644 --- a/src/common/impl/debug.c +++ b/src/common/impl/debug.c @@ -28,16 +28,19 @@ void ffDebugPrint(const char* file, int line, const char* format, ...) { } static FFThreadMutex debugMutex = FF_THREAD_MUTEX_INITIALIZER; - ffThreadMutexLock(&debugMutex); + // Saved before the lock and restored after the unlock: FF_DEBUG() is called from error paths + // that go on to read `errno`, so nothing this function does -- neither the lock nor the + // formatting -- may be allowed to leave its own value behind. int errno_ = errno; - static char errmsg_[1024]; + ffThreadMutexLock(&debugMutex); + static char errmsg_[1024]; // Don't increase stack size va_list args; va_start(args, format); vsnprintf(errmsg_, sizeof(errmsg_), format, args); va_end(args); fprintf(stderr, "[%s%4d, %s] %s\n", ffFindFileName(file), line, ffTimeToTimeStr(ffTimeGetNow()), errmsg_); - errno = errno_; ffThreadMutexUnlock(&debugMutex); + errno = errno_; } #if _WIN32