Remove the RFComm MCB from the ports when releasing it
Bug: 28849621
Change-Id: I3ce1c857d0d0a2c00c59d8f71b40685ae602dc29
diff --git a/stack/rfcomm/port_rfc.c b/stack/rfcomm/port_rfc.c
index fb9a146..aaad62a 100644
--- a/stack/rfcomm/port_rfc.c
+++ b/stack/rfcomm/port_rfc.c
@@ -228,7 +228,6 @@
p_port->error = PORT_START_FAILED;
rfc_release_multiplexer_channel (p_mcb);
- p_port->rfc.p_mcb = NULL;
/* Send event to the application */
if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECT_ERR))
diff --git a/stack/rfcomm/rfc_utils.c b/stack/rfcomm/rfc_utils.c
index e705f0d..2fa7ca8 100644
--- a/stack/rfcomm/rfc_utils.c
+++ b/stack/rfcomm/rfc_utils.c
@@ -198,8 +198,7 @@
**
** Function rfc_release_multiplexer_channel
**
-** Description This function returns existing or new control block for
-** the BD_ADDR.
+** Description Release a multiplexer control block
**
*******************************************************************************/
void rfc_release_multiplexer_channel (tRFC_MCB *p_mcb)
@@ -207,6 +206,12 @@
/* Remove the MCB from the mapping table */
rfc_save_lcid_mcb(NULL, p_mcb->lcid);
+ /* Remove the MCB from the ports */
+ for (int i = 0; i < MAX_RFC_PORTS; i++) {
+ if (rfc_cb.port.port[i].rfc.p_mcb == p_mcb)
+ rfc_cb.port.port[i].rfc.p_mcb = NULL;
+ }
+
rfc_timer_stop (p_mcb);
alarm_free(p_mcb->mcb_timer);