diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index 148704eeeeef2a..7e080f5246256e 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -297,27 +297,26 @@ 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; } std::unique_ptr ap_buffer_ptr(new wifi_ap_record_t[ap_number]); 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(); @@ -339,16 +338,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()