Skip to content

Commit 5049443

Browse files
committed
Ensure the connection structure is not freed when used by the connection thread
1 parent a587aa9 commit 5049443

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

common/gattlib_callback_connected_device.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ static gpointer _gattlib_connected_device_thread(gpointer data) {
5151
gattlib_context_t* conn_context = connection->context;
5252
const gchar *device_mac_address = org_bluez_device1_get_address(conn_context->device);
5353

54+
// Mutex to ensure the device is valid and not freed during its use
55+
g_mutex_lock(&connection->device_mutex);
56+
// Mutex to ensure the handler is valid
5457
g_rec_mutex_lock(&connection->on_connection.mutex);
5558

5659
if (!gattlib_has_valid_handler(&connection->on_connection)) {
@@ -63,6 +66,7 @@ static gpointer _gattlib_connected_device_thread(gpointer data) {
6366

6467
EXIT:
6568
g_rec_mutex_unlock(&connection->on_connection.mutex);
69+
g_mutex_unlock(&connection->device_mutex);
6670
return NULL;
6771
}
6872

0 commit comments

Comments
 (0)