From ecf7fbea1578c7854436cf3bd8d917ef99860536 Mon Sep 17 00:00:00 2001 From: liulinsong Date: Tue, 13 Aug 2024 16:45:23 +0800 Subject: [PATCH] Eliminate a potential bug If we send an event here, we may enter a new event loop and then the new event loop will process the events including socket events. As a result, after exiting the new event loop, the activeNotifierPos is same as the src->pollfds.count() and activeNotifierPos will be added by one in the old event loop. So there is a potential situation that activeNotifierPos will overflow if we have too many sockets and nested event loops. Although this situation is almost impossible, we can improve the code by little effort. That's it. --- src/corelib/kernel/qeventdispatcher_glib.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp index 1e906c4b275..d8d0f3a9252 100644 --- a/src/corelib/kernel/qeventdispatcher_glib.cpp +++ b/src/corelib/kernel/qeventdispatcher_glib.cpp @@ -68,10 +68,12 @@ static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpoin QEvent event(QEvent::SockAct); GSocketNotifierSource *src = reinterpret_cast(source); - for (src->activeNotifierPos = 0; src->activeNotifierPos < src->pollfds.size(); - ++src->activeNotifierPos) { + src->activeNotifierPos = 0; + while (src->activeNotifierPos < src->pollfds.size()) { GPollFDWithQSocketNotifier *p = src->pollfds.at(src->activeNotifierPos); + ++src->activeNotifierPos; + if ((p->pollfd.revents & p->pollfd.events) != 0) QCoreApplication::sendEvent(p->socketNotifier, &event); }