Skip to content

Commit fe0b931

Browse files
authored
Update BLEDevice.cpp
fix potential CORRUPT HEAP problem
1 parent a0ead19 commit fe0b931

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

libraries/BLE/src/BLEDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,15 @@ void BLEDevice::addPeerDevice(void* peer, bool _client, uint16_t conn_id) {
629629
m_connectedClientsMap.insert(std::pair<uint16_t, conn_status_t>(conn_id, status));
630630
}
631631

632+
//there may have some situation that invoking this function simultaneously, that will cause CORRUPT HEAP
633+
//let this function serializable
634+
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
632635
void BLEDevice::removePeerDevice(uint16_t conn_id, bool _client) {
636+
portENTER_CRITICAL(&mux);
633637
log_i("remove: %d, GATT role %s", conn_id, _client?"client":"server");
634638
if(m_connectedClientsMap.find(conn_id) != m_connectedClientsMap.end())
635639
m_connectedClientsMap.erase(conn_id);
640+
portEXIT_CRITICAL(&mux);
636641
}
637642

638643
/* multi connect support */

0 commit comments

Comments
 (0)