From 17869a544e2a3b2cdc61dfe87a96a8c1a3286fff Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 1 Mar 2013 15:47:15 +0100 Subject: [PATCH] fix spurious QWindowsPipeWriter deadlock We must check the return value of CancelIo(Ex) and only wait for a notification if it was successful. CancelIoEx can fail, if the handle is closed before the QWindowsPipeWriter destructor is called. Change-Id: I2dcc97052be917c69d18c277856374cbc07e2169 Reviewed-by: Friedemann Kleint Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qwindowspipereader.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp index efadb357a9..2cb5845768 100644 --- a/src/corelib/io/qwindowspipereader.cpp +++ b/src/corelib/io/qwindowspipereader.cpp @@ -64,7 +64,7 @@ QWindowsPipeReader::QWindowsPipeReader(QObject *parent) connect(dataReadNotifier, &QWinOverlappedIoNotifier::notified, this, &QWindowsPipeReader::notified); } -static void qt_cancelIo(HANDLE handle, OVERLAPPED *overlapped) +static bool qt_cancelIo(HANDLE handle, OVERLAPPED *overlapped) { typedef BOOL (WINAPI *PtrCancelIoEx)(HANDLE, LPOVERLAPPED); static PtrCancelIoEx ptrCancelIoEx = 0; @@ -74,16 +74,18 @@ static void qt_cancelIo(HANDLE handle, OVERLAPPED *overlapped) ptrCancelIoEx = PtrCancelIoEx(GetProcAddress(kernel32, "CancelIoEx")); } if (ptrCancelIoEx) - ptrCancelIoEx(handle, overlapped); + return ptrCancelIoEx(handle, overlapped); else - CancelIo(handle); + return CancelIo(handle); } QWindowsPipeReader::~QWindowsPipeReader() { if (readSequenceStarted) { - qt_cancelIo(handle, &overlapped); - dataReadNotifier->waitForNotified(-1, &overlapped); + if (qt_cancelIo(handle, &overlapped)) + dataReadNotifier->waitForNotified(-1, &overlapped); + else + qErrnoWarning("QWindowsPipeReader: qt_cancelIo on handle %x failed.", handle); } }