Diff between 36e398391b6de47cce7a72bece2da182c7c4c52e and e9c1c41ac195c885341f7a2e4968a8c62e2ce91a

Changed Files

File Additions Deletions Status
src/attrib-server.c +17 -28 modified
src/device.c +9 -5 modified

Full Patch

diff --git a/src/attrib-server.c b/src/attrib-server.c
index aa0012f..5f353df 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -1223,43 +1223,32 @@ guint attrib_channel_attach(GAttrib *attrib)
 	return channel->id;
 }
 
-static int channel_id_cmp(gconstpointer data, gconstpointer user_data)
+static struct gatt_channel *find_channel(guint id)
 {
-	const struct gatt_channel *channel = data;
-	guint id = GPOINTER_TO_UINT(user_data);
-
-	return channel->id - id;
-}
-
-gboolean attrib_channel_detach(GAttrib *attrib, guint id)
-{
-	struct gatt_server *server;
-	struct gatt_channel *channel;
-	GError *gerr = NULL;
-	GIOChannel *io;
-	bdaddr_t src;
 	GSList *l;
 
-	io = g_attrib_get_channel(attrib);
+	for (l = servers; l; l = g_slist_next(l)) {
+		struct gatt_server *server = l->data;
+		GSList *c;
 
-	bt_io_get(io, &gerr, BT_IO_OPT_SOURCE_BDADDR, &src, BT_IO_OPT_INVALID);
+		for (c = server->clients; c; c = g_slist_next(c)) {
+			struct gatt_channel *channel = c->data;
 
-	if (gerr != NULL) {
-		error("bt_io_get: %s", gerr->message);
-		g_error_free(gerr);
-		return FALSE;
+			if (channel->id == id)
+				return channel;
+		}
 	}
 
-	server = find_gatt_server(&src);
-	if (server == NULL)
-		return FALSE;
+	return NULL;
+}
 
-	l = g_slist_find_custom(server->clients, GUINT_TO_POINTER(id),
-								channel_id_cmp);
-	if (!l)
-		return FALSE;
+gboolean attrib_channel_detach(GAttrib *attrib, guint id)
+{
+	struct gatt_channel *channel;
 
-	channel = l->data;
+	channel = find_channel(id);
+	if (channel == NULL)
+		return FALSE;
 
 	g_attrib_unregister(channel->attrib, channel->id);
 	channel_remove(channel);
diff --git a/src/device.c b/src/device.c
index 59e4dea..2a5a883 100644
--- a/src/device.c
+++ b/src/device.c
@@ -512,11 +512,6 @@ static void gatt_client_cleanup(struct btd_device *device)
 
 static void attio_cleanup(struct btd_device *device)
 {
-	if (device->attachid) {
-		attrib_channel_detach(device->attrib, device->attachid);
-		device->attachid = 0;
-	}
-
 	if (device->att_disconn_id)
 		bt_att_unregister_disconnect(device->att,
 							device->att_disconn_id);
@@ -536,7 +531,16 @@ static void attio_cleanup(struct btd_device *device)
 
 	if (device->attrib) {
 		GAttrib *attrib = device->attrib;
+
 		device->attrib = NULL;
+
+		if (device->attachid) {
+			guint attachid = device->attachid;
+
+			device->attachid = 0;
+			attrib_channel_detach(attrib, attachid);
+		}
+
 		g_attrib_cancel_all(attrib);
 		g_attrib_unref(attrib);
 	}