Modbus RTU serial client: do not crash when a reply is deleted
If the user has explicitly deleted a QModbusReply object after the
request was sent via the serialport, the reading code could crash
when trying to access a deleted reply object when handling various
error conditions (like CRC mismatch and request/response mismatch).
I thought about different approaches of solving the issue.
For example, we could discard the received data if the top command
in the queue has a nullptr reply. Or we could remove the top command,
and try to match the received data with the next command.
Both these approaches could mean behavior change in some corner cases,
so I decided to fix it in the safest way and simply check if the reply
is available before accessing it.
As a drive-by: use `current` instead of `m_queue.first()`, becuase
it's a pre-existing reference to the same element of the queue.
Fixes: QTBUG-135791
Pick-to: 6.9 6.8 6.5
Change-Id: If20182aae1102712da61697853ca1d8c011bd22a
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>