SDL: stdlib: Fail if we can't create a mutex in SDL_CreateEnvironment().

From 52ef28aebadaf6fd3478cf06a8c3337c7214262d Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 10 Oct 2026 11:03:39 -0400
Subject: [PATCH] stdlib: Fail if we can't create a mutex in
 SDL_CreateEnvironment().

Even single-threaded platforms will successfully create a (no-op) mutex now.
---
 src/stdlib/SDL_getenv.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c
index ff32f632ae71d..7c09ce9437dfa 100644
--- a/src/stdlib/SDL_getenv.c
+++ b/src/stdlib/SDL_getenv.c
@@ -93,15 +93,19 @@ SDL_Environment *SDL_CreateEnvironment(bool populated)
         return NULL;
     }
 
+    env->lock = SDL_CreateMutex();
+    if (!env->lock) {
+        SDL_free(env);
+        return NULL;
+    }
+
     env->strings = SDL_CreateHashTable(0, false, SDL_HashString, SDL_KeyMatchString, SDL_DestroyHashKey, NULL);
     if (!env->strings) {
+        SDL_DestroyMutex(env->lock);
         SDL_free(env);
         return NULL;
     }
 
-    // Don't fail if we can't create a mutex (e.g. on a single-thread environment)  // !!! FIXME: single-threaded environments should still return a non-NULL, do-nothing object here. Check for failure!
-    env->lock = SDL_CreateMutex();
-
     if (populated) {
 #if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN)
         LPWCH strings = GetEnvironmentStringsW();