Don't try to create a semaphore for the mutex implementation if threads are disabled Fixes https://github.com/libsdl-org/SDL/issues/6344
diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c
index 42965aa..12cc580 100644
--- a/src/thread/generic/SDL_sysmutex.c
+++ b/src/thread/generic/SDL_sysmutex.c
@@ -40,7 +40,9 @@ SDL_CreateMutex(void)
SDL_mutex *mutex;
/* Allocate mutex memory */
- mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
+ mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex));
+
+#if !SDL_THREADS_DISABLED
if (mutex) {
/* Create the mutex semaphore, with initial value 1 */
mutex->sem = SDL_CreateSemaphore(1);
@@ -53,6 +55,8 @@ SDL_CreateMutex(void)
} else {
SDL_OutOfMemory();
}
+#endif /* !SDL_THREADS_DISABLED */
+
return mutex;
}