Skip to content

Commit 6aea023

Browse files
[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 <commits@restyled.io>
1 parent c9cfd3f commit 6aea023

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/platform/ESP32/ConfigurationManagerImpl.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <lib/support/CodeUtils.h>
3030
#include <platform/ConfigurationManager.h>
3131
#include <platform/ESP32/ESP32Config.h>
32+
#include <platform/ESP32/ESP32Utils.h>
3233
#include <platform/internal/GenericConfigurationManagerImpl.ipp>
3334

3435
#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
@@ -404,6 +405,22 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
404405
{
405406
CHIP_ERROR err;
406407

408+
// Unregistering the wifi and IP event handlers from the esp_default_event_loop()
409+
err = ESP32Utils::MapError(esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent));
410+
if (err != CHIP_NO_ERROR)
411+
{
412+
ChipLogError(DeviceLayer, "Failed to unregister IP event handler");
413+
}
414+
415+
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
416+
err =
417+
ESP32Utils::MapError(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent));
418+
if (err != CHIP_NO_ERROR)
419+
{
420+
ChipLogError(DeviceLayer, "Failed to unregister wifi event handler");
421+
}
422+
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
423+
407424
ChipLogProgress(DeviceLayer, "Performing factory reset");
408425

409426
// Erase all values in the chip-config NVS namespace.

0 commit comments

Comments
 (0)