From 9a413525e26ac3211079d9ada4132a01d190e33c Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Tue, 13 Dec 2022 22:19:44 +0800 Subject: [PATCH] event_handler: Allows removal of eventHandler in eventHandler->Handler (#23923) --- src/include/platform/internal/GenericPlatformManagerImpl.ipp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.ipp b/src/include/platform/internal/GenericPlatformManagerImpl.ipp index 7a46248e0eb312..4cee5dab0b5cd8 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.ipp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.ipp @@ -292,9 +292,11 @@ template void GenericPlatformManagerImpl::DispatchEventToApplication(const ChipDeviceEvent * event) { // Dispatch the event to each of the registered application event handlers. - for (AppEventHandler * eventHandler = mAppEventHandlerList; eventHandler != nullptr; eventHandler = eventHandler->Next) + for (AppEventHandler * eventHandler = mAppEventHandlerList; eventHandler != nullptr;) { + AppEventHandler * nextEventHandler = eventHandler->Next; eventHandler->Handler(event, eventHandler->Arg); + eventHandler = nextEventHandler; } }