diff --git a/src/device.c b/src/device.c
index 9736bb6..fb9c0e7 100644
--- a/src/device.c
+++ b/src/device.c
* attribute cache support can be built.
*/
struct gatt_db *db; /* GATT db cache */
+ unsigned int db_id;
struct bt_gatt_client *client; /* GATT client instance */
struct bt_gatt_server *server; /* GATT server instance */
unsigned int gatt_ready_id;
g_slist_free_full(device->svc_callbacks, svc_dev_remove);
/* Reset callbacks since the device is going to be freed */
- gatt_db_register(device->db, NULL, NULL, NULL, NULL);
+ gatt_db_unregister(device->db, device->db_id);
attio_cleanup(device);
device->adapter = adapter;
device->temporary = true;
- gatt_db_register(device->db, gatt_service_added, gatt_service_removed,
- device, NULL);
+ device->db_id = gatt_db_register(device->db, gatt_service_added,
+ gatt_service_removed, device, NULL);
return btd_device_ref(device);
}