From 9da58e9fb7014a6b069433a1484198032602fda4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 27 Jul 2024 09:34:49 -0700 Subject: [PATCH] Fixed storing a key in the persistent string hashtable that's about to be freed --- src/SDL_utils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SDL_utils.c b/src/SDL_utils.c index aaf721031a..b3584c8fbb 100644 --- a/src/SDL_utils.c +++ b/src/SDL_utils.c @@ -352,16 +352,16 @@ const char *SDL_GetPersistentString(const char *string) SDL_SetTLS(&SDL_string_storage, strings, SDL_FreePersistentStrings); } - const void *retval; - if (!SDL_FindInHashTable(strings, string, &retval)) { + const char *retval; + if (!SDL_FindInHashTable(strings, string, (const void **)&retval)) { char *new_string = SDL_strdup(string); if (!new_string) { return NULL; } // If the hash table insert fails, at least we can return the string we allocated + SDL_InsertIntoHashTable(strings, new_string, new_string); retval = new_string; - SDL_InsertIntoHashTable(strings, string, retval); } - return (const char *)retval; + return retval; }