Skip to content

Commit

Permalink
Ensure the connection structure is not freed when used by the connect…
Browse files Browse the repository at this point in the history
…ion thread
  • Loading branch information
oliviermartin committed Apr 4, 2024
1 parent a587aa9 commit 5049443
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/gattlib_callback_connected_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 5049443

Please sign in to comment.