SDL: Do a final pass freeing temporary memory when we quit.

From 9d47daef0a674b06f97be383f67b6e7bf406f41b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 3 Jul 2024 18:46:51 -0700
Subject: [PATCH] Do a final pass freeing temporary memory when we quit.

Fixes https://github.com/libsdl-org/SDL/issues/10169
---
 src/SDL.c                 | 2 ++
 src/events/SDL_events.c   | 2 +-
 src/events/SDL_events_c.h | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/SDL.c b/src/SDL.c
index 7814ad2062467..2957787244963 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -559,6 +559,8 @@ void SDL_Quit(void)
      */
     SDL_memset(SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount));
 
+    SDL_FlushEventMemory(0);
+
     SDL_CleanupTLS();
 
     SDL_FreeEnvironmentMemory();
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 20a5aa97da08e..069c8248e2c20 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -143,7 +143,7 @@ const char *SDL_AllocateEventString(const char *string)
     return NULL;
 }
 
-static void SDL_FlushEventMemory(Uint32 eventID)
+void SDL_FlushEventMemory(Uint32 eventID)
 {
     SDL_LockMutex(SDL_event_memory_lock);
     {
diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h
index 778af32cadbf0..cc544733c60ed 100644
--- a/src/events/SDL_events_c.h
+++ b/src/events/SDL_events_c.h
@@ -38,6 +38,7 @@
 /* Start and stop the event processing loop */
 extern int SDL_StartEventLoop(void);
 extern void SDL_StopEventLoop(void);
+extern void SDL_FlushEventMemory(Uint32 eventID);
 extern void SDL_QuitInterrupt(void);
 
 extern const char *SDL_AllocateEventString(const char *string);