From 26c0e35ee3e650e8ec182c205a5de8dcac7a7839 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 17 Aug 2021 17:56:30 -0700 Subject: [PATCH] [CI]: Fix random segmentation fault during event handling (#9010) * Fix random segmentation fault during event handling * Update for review comment --- src/system/WatchableEventManagerSelect.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/system/WatchableEventManagerSelect.cpp b/src/system/WatchableEventManagerSelect.cpp index 7bda3dc2631332..fef6d30709c767 100644 --- a/src/system/WatchableEventManagerSelect.cpp +++ b/src/system/WatchableEventManagerSelect.cpp @@ -351,11 +351,16 @@ void WatchableEventManager::HandleEvents() watchable->SetPendingIO( SocketEventsFromFDs(watchable->GetFD(), mSelected.mReadSet, mSelected.mWriteSet, mSelected.mErrorSet)); } - for (WatchableSocket * watchable = mAttachedSockets; watchable != nullptr; watchable = watchable->mAttachedNext) + + WatchableSocket * nextWatchableSocket = mAttachedSockets; + while (nextWatchableSocket != nullptr) { - if (watchable->mPendingIO.HasAny()) + WatchableSocket * currentWatchable = nextWatchableSocket; + nextWatchableSocket = nextWatchableSocket->mAttachedNext; + + if (currentWatchable->mPendingIO.HasAny()) { - watchable->InvokeCallback(); + currentWatchable->InvokeCallback(); } }