From d5cf34ef81302cdc3632859a41a3303a041b35f9 Mon Sep 17 00:00:00 2001 From: Kevin Schoedel <67607049+kpschoedel@users.noreply.github.com> Date: Thu, 9 Sep 2021 13:01:39 -0400 Subject: [PATCH] Fix EventHandlerDelegate crash (#9569) #### Problem 3a505010973c #9366 caused a crash. In `AddEventHandlerDelegate()`, `lDelegate` was accidentally a stack variable instead of a reference to the caller-supplied storage. This affects all platforms using LwIP. #### Change overview Add one small but important `&`. Fixes #9563 _ESP32&ESP32C3 crash on system layer_ #### Testing all-clusters-app on M5Stack --- src/system/SystemLayerImplLwIP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/SystemLayerImplLwIP.cpp b/src/system/SystemLayerImplLwIP.cpp index b94745659deeb1..e7032941b524d5 100644 --- a/src/system/SystemLayerImplLwIP.cpp +++ b/src/system/SystemLayerImplLwIP.cpp @@ -147,7 +147,7 @@ CHIP_ERROR LayerImplLwIP::HandleSystemLayerEvent(Object & aTarget, EventType aEv CHIP_ERROR LayerImplLwIP::AddEventHandlerDelegate(EventHandlerDelegate & aDelegate) { - LwIPEventHandlerDelegate lDelegate = static_cast(aDelegate); + LwIPEventHandlerDelegate & lDelegate = static_cast(aDelegate); VerifyOrReturnError(lDelegate.GetFunction() != nullptr, CHIP_ERROR_INVALID_ARGUMENT); lDelegate.Prepend(mEventDelegateList); return CHIP_NO_ERROR;