Use 0/nullptr to indicate invalid Windows event handle in QLocalServer

The CreateEvent function returns NULL/nullptr if it failed, not
INVALID_HANDLE_VALUE(-1).

Change-Id: I7fb94061f4e14c014bf63acb53d3eee8f295eb66
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Jøger Hansegård 2025-01-13 19:49:18 +01:00
parent 0b7ff3d0a7
commit 604b6d60d0
3 changed files with 4 additions and 3 deletions

View File

@ -197,7 +197,7 @@ qintptr QLocalServer::socketDescriptor() const
return d->tcpServer.socketDescriptor();
#elif defined(Q_OS_WIN)
const auto handle = d->connectionEventNotifier->handle();
return handle != INVALID_HANDLE_VALUE ? qintptr(handle) : -1;
return handle ? qintptr(handle) : -1;
#else
return d->socketNotifier->socket();
#endif

View File

@ -76,7 +76,7 @@ public:
bool addListener();
std::vector<std::unique_ptr<Listener>> listeners;
HANDLE eventHandle;
HANDLE eventHandle = nullptr;
QWinEventNotifier *connectionEventNotifier;
#else
void setError(const QString &function);

View File

@ -215,7 +215,7 @@ bool QLocalServerPrivate::listen(const QString &name)
// Use only one event for all listeners of one socket.
// The idea is that listener events are rare, so polling all listeners once in a while is
// cheap compared to waiting for N additional events in each iteration of the main loop.
eventHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
eventHandle = CreateEvent(NULL, TRUE, FALSE, NULL); // If the function fails, the return value is NULL
connectionEventNotifier = new QWinEventNotifier(eventHandle , q);
q->connect(connectionEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onNewConnection()));
@ -282,6 +282,7 @@ void QLocalServerPrivate::closeServer()
connectionEventNotifier->deleteLater();
connectionEventNotifier = 0;
CloseHandle(eventHandle);
eventHandle = nullptr;
for (size_t i = 0; i < listeners.size(); ++i)
CloseHandle(listeners[i]->handle);
listeners.clear();