diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2016-09-09 08:53:20 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2016-09-21 18:58:58 +0000 |
commit | fcd6ac231d160afd5c11cc5ef515dcc61c3eca3f (patch) | |
tree | 7c9d3c37f8faaff92fbf7c47993cbf5cb78eed6e | |
parent | a840a9ea5548044c1901f5d4008aaa00553f99d7 (diff) | |
download | qtserialport-fcd6ac231d160afd5c11cc5ef515dcc61c3eca3f.tar.gz |
Fix crash after closing of ejected device on Linux
When the user calls QSP::close() in a slot which is connected to the
QSP::error() signal, then the application is crashed. The reason is that
we emit the QSP::error() signal before than we call QRingBuffer::chop()
of an internal read buffer, which becomes invalid after the
QIODevice::close() called. Therefore, we need just call
QRingBuffer::chop() before than the QSP::error() signal will be emitted.
Task-number: QTBUG-55847
Change-Id: If536f9cf5cbc1b813d3642bdf9be0867e06368e8
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 8e06ada..fafe8c5 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -778,6 +778,8 @@ bool QSerialPortPrivate::readNotification() char *ptr = buffer.reserve(bytesToRead); const qint64 readBytes = readFromPort(ptr, bytesToRead); + buffer.chop(bytesToRead - qMax(readBytes, qint64(0))); + if (readBytes <= 0) { QSerialPortErrorInfo error = getSystemError(); if (error.errorCode != QSerialPort::ResourceError) @@ -785,12 +787,9 @@ bool QSerialPortPrivate::readNotification() else setReadNotificationEnabled(false); setError(error); - buffer.chop(bytesToRead); return false; } - buffer.chop(bytesToRead - qMax(readBytes, qint64(0))); - newBytes = buffer.size() - newBytes; // If read buffer is full, disable the read port notifier. |