diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index 148704eeeeef2a..01d8c12c0acf66 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -309,6 +309,10 @@ void ESPWiFiDriver::OnScanWiFiNetworkDone() } return; } + + // Since this is the dynamic memory allocation, restrict it to a configured limit + ap_number = std::min(static_cast(CHIP_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS), ap_number); + std::unique_ptr ap_buffer_ptr(new wifi_ap_record_t[ap_number]); if (ap_buffer_ptr == NULL) {