From 90756b542f2b5448a917bde2ec8e22bffd1500a1 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 2 Jun 2026 15:50:32 -0700
Subject: [PATCH] Fixed some log related thread-safety warnings
---
src/SDL_log.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/SDL_log.c b/src/SDL_log.c
index 0d1ee3f91c351..6295fc68effe3 100644
--- a/src/SDL_log.c
+++ b/src/SDL_log.c
@@ -180,11 +180,15 @@ static void SDL_CheckInitLog(void)
static void CleanupLogPriorities(void)
{
+ SDL_LockMutex(SDL_log_lock);
+
while (SDL_loglevels) {
SDL_LogLevel *entry = SDL_loglevels;
SDL_loglevels = entry->next;
SDL_free(entry);
}
+
+ SDL_UnlockMutex(SDL_log_lock);
}
void SDL_SetLogPriorities(SDL_LogPriority priority)
@@ -339,6 +343,8 @@ static void ParseLogPriorities(const char *hint)
return;
}
+ SDL_LockMutex(SDL_log_lock);
+
for (name = hint; name; name = next) {
const char *sep = SDL_strchr(name, '=');
if (!sep) {
@@ -371,6 +377,8 @@ static void ParseLogPriorities(const char *hint)
}
}
}
+
+ SDL_UnlockMutex(SDL_log_lock);
}
void SDL_ResetLogPriorities(void)
@@ -431,12 +439,16 @@ void SDL_ResetLogPriorities(void)
static void CleanupLogPrefixes(void)
{
+ SDL_LockMutex(SDL_log_function_lock);
+
for (int i = 0; i < SDL_arraysize(SDL_priority_prefixes); ++i) {
if (SDL_priority_prefixes[i]) {
SDL_free(SDL_priority_prefixes[i]);
SDL_priority_prefixes[i] = NULL;
}
}
+
+ SDL_UnlockMutex(SDL_log_function_lock);
}
static const char *GetLogPriorityPrefix(SDL_LogPriority priority)