sdl12-compat: Close audio device in SDL_Quit{,Subsystem}

From 9ab4eff9c08c9310c5a96ddcfc94100cf8ef65f0 Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Fri, 11 Jun 2021 17:36:40 +0800
Subject: [PATCH] Close audio device in SDL_Quit{,Subsystem}

Given we allocate and use a bunch of wrappers around the SDL audio
device, we should shut it down explicitly on quit.

The simplest way to implement this was to just call our SDL_CloseAudio()
implementation in SDL_QuitSubsystem(), which require making it robust
against closing an already closed audio device.

This fixes a sporadic null pointer access in the audio callback on
DOSBox on one of my machines.
---
 src/SDL12_compat.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 851ee7b..8cfc350 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -1710,6 +1710,10 @@ SDL_QuitSubSystem(Uint32 sdl12flags)
         QuitCDSubsystem();
     }
 
+    if (sdl12flags & SDL12_INIT_AUDIO) {
+        SDL_CloseAudio();
+    }
+
     if (sdl12flags & SDL12_INIT_VIDEO) {
         Quit12Video();
     }
@@ -6775,12 +6779,11 @@ SDL_CloseAudio(void)
     SDL20_LockAudio();
     if (audio_cbdata) {
         audio_cbdata->app_callback_opened = SDL_FALSE;
+        SDL20_FreeAudioStream(audio_cbdata->app_callback_stream);
+        audio_cbdata->app_callback_stream = NULL;
     }
     SDL20_UnlockAudio();
 
-    SDL20_FreeAudioStream(audio_cbdata->app_callback_stream);
-    audio_cbdata->app_callback_stream = NULL;
-
     CloseSDL2AudioDevice();
 }