diff --git a/android/hidhost.c b/android/hidhost.c
index 6c0930f..8bd3455 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
close(fd);
}
-static void hid_device_free(struct hid_device *dev)
+static void hid_device_free(void *data)
{
+ struct hid_device *dev = data;
+
if (dev->ctrl_watch > 0)
g_source_remove(dev->ctrl_watch);
uhid_destroy(dev->uhid_fd);
g_free(dev->rd_data);
+ g_free(dev);
+}
+static void hid_device_remove(struct hid_device *dev)
+{
devices = g_slist_remove(devices, dev);
- g_free(dev);
+ hid_device_free(dev);
}
static void handle_uhid_output(struct hid_device *dev,
if (dev->ctrl_io && !(cond & G_IO_NVAL))
g_io_channel_shutdown(dev->ctrl_io, TRUE, NULL);
- hid_device_free(dev);
+ hid_device_remove(dev);
return FALSE;
}
if (dev->intr_io && !(cond & G_IO_NVAL))
g_io_channel_shutdown(dev->intr_io, TRUE, NULL);
- hid_device_free(dev);
+ hid_device_remove(dev);
return FALSE;
}
failed:
bt_hid_notify_state(dev, state);
- hid_device_free(dev);
+ hid_device_remove(dev);
}
static void control_connect_cb(GIOChannel *chan, GError *conn_err,
return;
failed:
- hid_device_free(dev);
+ hid_device_remove(dev);
}
static void hid_sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
fail:
bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTED);
- hid_device_free(dev);
+ hid_device_remove(dev);
}
static void hid_sdp_did_search_cb(sdp_list_t *recs, int err, gpointer data)
fail:
bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTED);
- hid_device_free(dev);
+ hid_device_remove(dev);
}
static void bt_hid_connect(const void *buf, uint16_t len)
if (bt_search_service(&adapter_addr, &dev->dst, &uuid,
hid_sdp_did_search_cb, dev, NULL, 0) < 0) {
error("Failed to search DeviceID SDP details");
- hid_device_free(dev);
+ hid_device_remove(dev);
status = HAL_STATUS_FAILED;
goto failed;
}
if (bt_search_service(&src, &dev->dst, &uuid,
hid_sdp_did_search_cb, dev, NULL, 0) < 0) {
error("failed to search did sdp details");
- hid_device_free(dev);
+ hid_device_remove(dev);
return;
}
return true;
}
-static void free_hid_devices(gpointer data, gpointer user_data)
-{
- struct hid_device *dev = data;
-
- hid_device_free(dev);
-}
-
void bt_hid_unregister(void)
{
DBG("");
- g_slist_foreach(devices, free_hid_devices, NULL);
+ g_slist_free_full(devices, hid_device_free);
devices = NULL;
if (ctrl_io) {