aboutsummaryrefslogtreecommitdiff
path: root/audio/yabridge/fix-libdbus-connection.patch
blob: 4acbee29278935e7c30a726fcaf4b4c9804886b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
commit 8d508dc2fefe9745ffa9cb14e1d7519a7852aa95
Author: Robbert van der Helm <mail@robbertvanderhelm.nl>
Date:   Sun Apr 7 22:49:00 2024 +0200

    Fix segfault destroying libdbus connection

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a1739b3d..429880a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic
 Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [Unreleased]
+
+### Fixed
+
+- Fixed a potential segfault when unloading yabridge.
+
 ## [5.1.0] - 2023-12-23
 
 ### Added
diff --git a/src/common/notifications.cpp b/src/common/notifications.cpp
index 403103bf..654b6c83 100644
--- a/src/common/notifications.cpp
+++ b/src/common/notifications.cpp
@@ -57,9 +57,19 @@ std::mutex libdbus_mutex;
 LIBDBUS_FUNCTIONS
 #undef X
 
+/**
+ * The deleter used for `libdbus_connection`. `libdbus_connection` can't
+ * directly reference `libdbus_connection_unref` directly because it will not
+ * yet have been initialized until just before `libdbus_connection` gets
+ * initialized.
+ */
+static void close_dbus_connection(DBusConnection* connection) {
+    libdbus_connection_unref(connection);
+}
+
 std::unique_ptr<DBusConnection, void (*)(DBusConnection*)> libdbus_connection(
     nullptr,
-    libdbus_connection_unref);
+    close_dbus_connection);
 
 /**
  * Try to set up D-Bus. Returns `false` if a function could not be resolved or