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(); } }