From 6aea023290d7ed2f85b68e2ad42d3cb498e85593 Mon Sep 17 00:00:00 2001 From: shripad621git <79364691+shripad621git@users.noreply.github.com> Date: Mon, 3 Jun 2024 20:58:10 +0530 Subject: [PATCH] [ESP32] Unregistering wifi and IP event handlers before factory reset to avoid random crashes due to PostEventQueue failure. (#33684) (#33702) * Unregistering wifi and IP event handlers before factory reset to avoid random crashes due to post event queue failure * Restyled by clang-format * Fix the CI failure in lit-icd app --------- Co-authored-by: Restyled.io --- src/platform/ESP32/ConfigurationManagerImpl.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 62dc02cba74628..37995f4d185a33 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET @@ -404,6 +405,22 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; + // Unregistering the wifi and IP event handlers from the esp_default_event_loop() + err = ESP32Utils::MapError(esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent)); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to unregister IP event handler"); + } + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + err = + ESP32Utils::MapError(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent)); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to unregister wifi event handler"); + } +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI + ChipLogProgress(DeviceLayer, "Performing factory reset"); // Erase all values in the chip-config NVS namespace.