SDL: dbus: fix spurious leak reports with SDL_SHUTDOWN_DBUS_ON_QUIT=0

From c4c185283fadd2820d048a3061dbdc2c3bc4285e Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Tue, 4 Feb 2025 17:36:45 -0600
Subject: [PATCH] dbus: fix spurious leak reports with
 SDL_SHUTDOWN_DBUS_ON_QUIT=0

---
 src/core/linux/SDL_dbus.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/core/linux/SDL_dbus.c b/src/core/linux/SDL_dbus.c
index e0ffea3c5d3ea..9a2fc1ea53194 100644
--- a/src/core/linux/SDL_dbus.c
+++ b/src/core/linux/SDL_dbus.c
@@ -189,10 +189,16 @@ void SDL_DBus_Quit(void)
         if (dbus.shutdown) {
             dbus.shutdown();
         }
+
+        UnloadDBUSLibrary();
+    } else {
+        /* Leaving libdbus loaded when skipping dbus_shutdown() avoids
+         * spurious leak warnings from LeakSanitizer on internal D-Bus
+         * allocations that would be freed by dbus_shutdown(). */
+        dbus_handle = NULL;
     }
 
     SDL_zero(dbus);
-    UnloadDBUSLibrary();
     if (inhibit_handle) {
         SDL_free(inhibit_handle);
         inhibit_handle = NULL;