Diff between 4a10293051f43792fe340c493b5e794b55a7bc99 and 5b143edffc065678bd81a74aba7167d9ebf5ca7f

Changed Files

File Additions Deletions Status
src/shared/hci.c +11 -3 modified

Full Patch

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
@@ -185,21 +185,29 @@ static void process_response(struct bt_hci *hci, uint16_t opcode,
 {
 	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)