diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index e2ef8bb660ed0b..80e54d74803e7e 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -345,6 +345,10 @@ void ESPWiFiDriver::OnScanWiFiNetworkDone() mpScanCallback = nullptr; 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) {