From ab9c68d9ffc1fd53f29a9ce0e51d26a9f43b9b95 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 11 Sep 2024 12:33:31 +0100 Subject: [PATCH] pipewire: Always destroy hotplug loop during deinitialization We always need to destroy the hotplug loop and its associated resources (if created) before we can deinitialize and unload the Pipewire library. In the happy path where everything worked correctly, this means we will call hotplug_loop_destroy() twice (once from PIPEWIRE_DeinitializeStart() and a second time from PIPEWIRE_Deinitialize()), but that's OK, because it's idempotent and so will do nothing the second time. In error-handling code paths, this avoids needing to remember to call hotplug_loop_destroy() explicitly, which should make it easier to avoid bugs like #10787. Signed-off-by: Simon McVittie --- src/audio/pipewire/SDL_pipewire.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c index fa58a5c12..1cfe9a8d1 100644 --- a/src/audio/pipewire/SDL_pipewire.c +++ b/src/audio/pipewire/SDL_pipewire.c @@ -1215,6 +1215,7 @@ static void PIPEWIRE_DeinitializeStart(void) static void PIPEWIRE_Deinitialize(void) { if (pipewire_initialized) { + hotplug_loop_destroy(); deinit_pipewire_library(); pipewire_initialized = false; } @@ -1230,7 +1231,6 @@ static bool PipewireInitialize(SDL_AudioDriverImpl *impl) pipewire_initialized = true; if (!hotplug_loop_init()) { - hotplug_loop_destroy(); PIPEWIRE_Deinitialize(); return false; } @@ -1271,7 +1271,6 @@ static bool PIPEWIRE_PREFERRED_Init(SDL_AudioDriverImpl *impl) PIPEWIRE_pw_thread_loop_unlock(hotplug_loop); if (no_devices || !pipewire_core_version_at_least(1, 0, 0)) { - hotplug_loop_destroy(); PIPEWIRE_Deinitialize(); return false; }