diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index 01d8c12c0acf66..785768a1f89195 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -297,16 +297,18 @@ CHIP_ERROR ESPWiFiDriver::StartScanWiFiNetworks(ByteSpan ssid) void ESPWiFiDriver::OnScanWiFiNetworkDone() { + if (!mpScanCallback) + { + ChipLogProgress(DeviceLayer, "No scan callback"); + return; + } uint16_t ap_number; esp_wifi_scan_get_ap_num(&ap_number); if (!ap_number) { ChipLogProgress(DeviceLayer, "No AP found"); - if (mpScanCallback != nullptr) - { - mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), nullptr); - mpScanCallback = nullptr; - } + mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), nullptr); + mpScanCallback = nullptr; return; } @@ -317,11 +319,8 @@ void ESPWiFiDriver::OnScanWiFiNetworkDone() if (ap_buffer_ptr == NULL) { ChipLogError(DeviceLayer, "can't malloc memory for ap_list_buffer"); - if (mpScanCallback) - { - mpScanCallback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); - mpScanCallback = nullptr; - } + mpScanCallback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); + mpScanCallback = nullptr; return; } wifi_ap_record_t * ap_list_buffer = ap_buffer_ptr.get(); @@ -343,16 +342,19 @@ void ESPWiFiDriver::OnScanWiFiNetworkDone() { ap_buffer_ptr.release(); } - } - else - { - ChipLogError(DeviceLayer, "can't get ap_records "); - if (mpScanCallback) + else { + ChipLogError(DeviceLayer, "can't schedule the scan result processing"); mpScanCallback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); mpScanCallback = nullptr; } } + else + { + ChipLogError(DeviceLayer, "can't get ap_records "); + mpScanCallback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); + mpScanCallback = nullptr; + } } void ESPWiFiDriver::OnNetworkStatusChange()