SDL: audio: Fixed locking in SDL_AudioDeviceDisconnected

From e518149d144c5f391a29a8c88a8d7a807f88d6be Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 3 Jul 2023 20:32:55 -0400
Subject: [PATCH] audio: Fixed locking in SDL_AudioDeviceDisconnected

---
 src/audio/SDL_audio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index d60ccb5f2e8a..aa1d66d4bc35 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -330,6 +330,7 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
 
     // if the current default device is going down, mark it as dead but keep it around until a replacement is decided upon, so we can migrate logical devices to it.
     if ((device->instance_id == current_audio.default_output_device_id) || (device->instance_id == current_audio.default_capture_device_id)) {
+        SDL_LockMutex(device->lock);  // make sure nothing else is messing with the device before continuing.
         SDL_AtomicSet(&device->zombie, 1);
         SDL_AtomicSet(&device->shutdown, 1);  // tell audio thread to terminate, but don't mark it condemned, so the thread won't destroy the device. We'll join on the audio thread later.
 
@@ -341,6 +342,7 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
                 DisconnectLogicalAudioDevice(logdev);
             }
         }
+        SDL_UnlockMutex(device->lock);  // make sure nothing else is messing with the device before continuing.
         return;  // done for now. Come back when a new default device is chosen!
     }