Unverified Commit bb8c8559 authored by Curry's avatar Curry Committed by GitHub

Fix potential CORRUPT HEAP problem on libraries/BLE/src/BLEDevice.cpp (#7597)

* Update BLEDevice.cpp

fix potential CORRUPT HEAP problem

* move mux to BLEDevice class
parent 94fd529e
......@@ -629,10 +629,15 @@ void BLEDevice::addPeerDevice(void* peer, bool _client, uint16_t conn_id) {
m_connectedClientsMap.insert(std::pair<uint16_t, conn_status_t>(conn_id, status));
}
//there may have some situation that invoking this function simultaneously, that will cause CORRUPT HEAP
//let this function serializable
portMUX_TYPE BLEDevice::mux = portMUX_INITIALIZER_UNLOCKED;
void BLEDevice::removePeerDevice(uint16_t conn_id, bool _client) {
portENTER_CRITICAL(&mux);
log_i("remove: %d, GATT role %s", conn_id, _client?"client":"server");
if(m_connectedClientsMap.find(conn_id) != m_connectedClientsMap.end())
m_connectedClientsMap.erase(conn_id);
portEXIT_CRITICAL(&mux);
}
/* multi connect support */
......
......@@ -73,6 +73,7 @@ private:
static BLEAdvertising* m_bleAdvertising;
static esp_gatt_if_t getGattcIF();
static std::map<uint16_t, conn_status_t> m_connectedClientsMap;
static portMUX_TYPE mux;
static void gattClientEventHandler(
esp_gattc_cb_event_t event,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment