diff --git a/src/shared/hci.c b/src/shared/hci.c
index bfee4ab..262e93d 100644
--- a/src/shared/hci.c
+++ b/src/shared/hci.c
{
struct cmd *cmd;
- if (opcode == BT_HCI_CMD_NOP)
- goto done;
+ if (opcode == BT_HCI_CMD_NOP) {
+ wakeup_writer(hci);
+ return;
+ }
cmd = queue_remove_if(hci->rsp_queue, match_cmd_opcode,
UINT_TO_PTR(opcode));
if (!cmd)
return;
+ /* Take a reference before calling the callback since that can unref
+ * its reference destroying the instance.
+ */
+ bt_hci_ref(hci);
+
if (cmd->callback)
cmd->callback(data, size, cmd->user_data);
cmd_free(cmd);
-done:
wakeup_writer(hci);
+
+ bt_hci_unref(hci);
}
static void process_notify(void *data, void *user_data)