diff --git a/src/classic/hfp.c b/src/classic/hfp.c index b3786d923..6de794ef3 100644 --- a/src/classic/hfp.c +++ b/src/classic/hfp.c @@ -561,7 +561,15 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet // data: event (8), len(8), address(48), channel (8), rfcomm_cid (16) rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr); hfp_connection = provide_hfp_connection_context_for_bd_addr(event_addr); - if (!hfp_connection || hfp_connection->state != HFP_IDLE) return; + if (!hfp_connection){ + log_info("hfp: no memory to accept incoming connection - decline"); + rfcomm_decline_connection(rfcomm_event_incoming_connection_get_rfcomm_cid(packet)); + return; + } + if (hfp_connection->state != HFP_IDLE) { + log_error("hfp: incoming connection but state != HFP_IDLE"); + return; + } hfp_connection->rfcomm_cid = rfcomm_event_incoming_connection_get_rfcomm_cid(packet); hfp_connection->state = HFP_W4_RFCOMM_CONNECTED;