mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 07:27:19 +08:00
Fixed storing a key in the persistent string hashtable that's about to be freed
This commit is contained in:
+4
-4
@@ -352,16 +352,16 @@ const char *SDL_GetPersistentString(const char *string)
|
|||||||
SDL_SetTLS(&SDL_string_storage, strings, SDL_FreePersistentStrings);
|
SDL_SetTLS(&SDL_string_storage, strings, SDL_FreePersistentStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *retval;
|
const char *retval;
|
||||||
if (!SDL_FindInHashTable(strings, string, &retval)) {
|
if (!SDL_FindInHashTable(strings, string, (const void **)&retval)) {
|
||||||
char *new_string = SDL_strdup(string);
|
char *new_string = SDL_strdup(string);
|
||||||
if (!new_string) {
|
if (!new_string) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the hash table insert fails, at least we can return the string we allocated
|
// 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;
|
retval = new_string;
|
||||||
SDL_InsertIntoHashTable(strings, string, retval);
|
|
||||||
}
|
}
|
||||||
return (const char *)retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user