summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
}
}
}