From 411582c710097dbc31b7b3e47ab0eb8cc5568b8c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 28 Sep 2022 09:22:17 -0400 Subject: [PATCH] coreaudio: Don't crash on shutdown in a race condition. Fixed #6159. --- src/audio/coreaudio/SDL_coreaudio.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m index 4d3575657..7caa3f479 100644 --- a/src/audio/coreaudio/SDL_coreaudio.m +++ b/src/audio/coreaudio/SDL_coreaudio.m @@ -523,8 +523,16 @@ outputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffe { SDL_AudioDevice *this = (SDL_AudioDevice *) inUserData; + /* This flag is set before this->mixer_lock is destroyed during + shutdown, so check it before grabbing the mutex, and then check it + again _after_ in case we blocked waiting on the lock. */ + if (SDL_AtomicGet(&this->shutdown)) { + return; /* don't do anything, since we don't even want to enqueue this buffer again. */ + } + SDL_LockMutex(this->mixer_lock); + /* !!! FIXME: why do we have this->hidden->shutdown when this->shutdown exists? */ if (SDL_AtomicGet(&this->hidden->shutdown)) { SDL_UnlockMutex(this->mixer_lock); return; /* don't do anything, since we don't even want to enqueue this buffer again. */