Ensure the connection structure is not freed when used by the connection thread

pull/277/head 0.5.2
Olivier Martin 2024-04-04 23:48:43 +02:00
parent a587aa9dfa
commit 5049443704
1 changed files with 4 additions and 0 deletions

View File

@ -51,6 +51,9 @@ static gpointer _gattlib_connected_device_thread(gpointer data) {
gattlib_context_t* conn_context = connection->context;
const gchar *device_mac_address = org_bluez_device1_get_address(conn_context->device);
// Mutex to ensure the device is valid and not freed during its use
g_mutex_lock(&connection->device_mutex);
// Mutex to ensure the handler is valid
g_rec_mutex_lock(&connection->on_connection.mutex);
if (!gattlib_has_valid_handler(&connection->on_connection)) {
@ -63,6 +66,7 @@ static gpointer _gattlib_connected_device_thread(gpointer data) {
EXIT:
g_rec_mutex_unlock(&connection->on_connection.mutex);
g_mutex_unlock(&connection->device_mutex);
return NULL;
}