diff --git a/src/adapter.c b/src/adapter.c
index e553626..6255da6 100644
--- a/src/adapter.c
+++ b/src/adapter.c
return FALSE;
}
-static void discovery_free(void *data)
-{
- struct discovery_client *client = data;
-
- DBG("owner %s", client->owner);
-
- g_dbus_remove_watch(dbus_conn, client->watch);
-}
-
static void discovery_destroy(void *user_data)
{
struct discovery_client *client = user_data;
cancel_passive_scanning(adapter);
- if (adapter->discovery_list) {
- g_slist_free_full(adapter->discovery_list, discovery_free);
- adapter->discovery_list = NULL;
+ while (adapter->discovery_list) {
+ struct discovery_client *client;
- adapter->discovering = false;
+ client = adapter->discovery_list->data;
+
+ /* g_dbus_remove_watch will remove the client from the
+ * adapter's list and free it using the discovery_destroy
+ * function.
+ */
+ g_dbus_remove_watch(dbus_conn, client->watch);
}
+ adapter->discovering = false;
+
while (adapter->connections) {
struct btd_device *device = adapter->connections->data;
adapter_remove_connection(adapter, device);