summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-06-25 19:38:18 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-28 10:28:49 +0000
commitad6df4b3430de9ca5e3bbe809dee88f7b49591f1 (patch)
tree50add1a4567e06d381d48eee4dc9bff750d81fe9
parenta1ab6faf4c12ac92f878dfd00e9d046e676fc255 (diff)
Windows: guard against closing the connection while processing incoming data
Before the patch we could end up using an already deleted QWinOverlappedIoNotifier instance if the incoming queue has more than one message, and the user decides to close the connection (and so delete the notifier) before processing all of them. This patch adds an explicit check that the QWinOverlappedIoNotifier instance is still valid. This commit amends f3a306a30fc4f40d1c96fee0ed44517fe8b43d76 Task-number: QTBUG-101444 Change-Id: Ieae622d248629827ed627bc9c17f7b5be491b717 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 089f1cd197e93c216aae094ffbca2b4beacf57b8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/serialport/qwinoverlappedionotifier.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/serialport/qwinoverlappedionotifier.cpp b/src/serialport/qwinoverlappedionotifier.cpp
index 65d63bba..06f2b614 100644
--- a/src/serialport/qwinoverlappedionotifier.cpp
+++ b/src/serialport/qwinoverlappedionotifier.cpp
@@ -382,9 +382,12 @@ void QWinOverlappedIoNotifierPrivate::_q_notified()
QQueue<IOResult> values;
results.swap(values);
ReleaseMutex(hResultsMutex);
- while (!values.empty()) {
+ // 'q' can go out of scope if the user decides to close the serial port
+ // while processing some answer. So we need to guard against that.
+ QPointer<QWinOverlappedIoNotifier> qptr(q);
+ while (!values.empty() && qptr) {
IOResult ioresult = values.dequeue();
- emit q->notified(ioresult.numberOfBytes, ioresult.errorCode, ioresult.overlapped);
+ emit qptr->notified(ioresult.numberOfBytes, ioresult.errorCode, ioresult.overlapped);
}
}
}