Don't create a TLS error buffer if we're just clearing the error

Fixes https://github.com/libsdl-org/SDL/issues/7600
This commit is contained in:
Sam Lantinga
2023-12-16 21:27:44 -08:00
parent 240e7747c8
commit 72b7acfe8a
3 changed files with 18 additions and 6 deletions

View File

@@ -212,7 +212,7 @@ static void SDLCALL SDL_FreeErrBuf(void *data)
#endif
/* Routine to get the thread-specific error variable */
SDL_error *SDL_GetErrBuf(void)
SDL_error *SDL_GetErrBuf(SDL_bool create)
{
#ifdef SDL_THREADS_DISABLED
return SDL_GetStaticErrBuf();
@@ -223,6 +223,10 @@ SDL_error *SDL_GetErrBuf(void)
const SDL_error *ALLOCATION_IN_PROGRESS = (SDL_error *)-1;
SDL_error *errbuf;
if (!tls_errbuf && !create) {
return NULL;
}
/* tls_being_created is there simply to prevent recursion if SDL_CreateTLS() fails.
It also means it's possible for another thread to also use SDL_global_errbuf,
but that's very unlikely and hopefully won't cause issues.