diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2018-10-18 09:40:35 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2018-10-22 07:10:03 +0000 |
commit | 864e4a8ab514ddcd7f79106a6b447f7a1d5b5d4e (patch) | |
tree | eb6d3429be0d012c0484bab78750af23ffb1fda3 | |
parent | b5c415eb612d05f7fe690eff361a616d0cabbc7e (diff) |
Fix case of accessing deleted memory
If the current QModbusRtuSerialMaster instance is deleted, the
interFrameDelay timer may still be active and trigger the associated
lambda. Since the lambda calls back into the deleted class instance,
a crash may occur. Adding the public class instance as context to
the singleshot connect ensures that the lambda is not called if the class
instance was deleted already.
Fixes: QTBUG-65684
Change-Id: Ic7d90ba68a1533e6de50c61117f5de8dc5e048b4
Reviewed-by: André Hartmann <aha_1980@gmx.de>
-rw-r--r-- | src/serialbus/qmodbusrtuserialmaster_p.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/serialbus/qmodbusrtuserialmaster_p.h b/src/serialbus/qmodbusrtuserialmaster_p.h index 770a39b..9a75de5 100644 --- a/src/serialbus/qmodbusrtuserialmaster_p.h +++ b/src/serialbus/qmodbusrtuserialmaster_p.h @@ -265,9 +265,11 @@ public: } void scheduleNextRequest() { + Q_Q(QModbusRtuSerialMaster); + m_state = Schedule; m_serialPort->clear(QSerialPort::AllDirections); - QTimer::singleShot(m_interFrameDelayMilliseconds, [this]() { processQueue(); }); + QTimer::singleShot(m_interFrameDelayMilliseconds, q, [this]() { processQueue(); }); } QModbusReply *enqueueRequest(const QModbusRequest &request, int serverAddress, |