From 3650975e566d13483869d1213e434a1ce609335b Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 24 Nov 2021 05:30:41 +0100 Subject: Fix crash when sending ack on removed connection The emit might interrupt our function and causes us to return to the event loop. In that time frame the other and might close the connection, causing our connection to be removed. In that case we call writeAck on a dangling pointer, in the best case causing a crash. So lets finish our business before emitting our signal. fixes #138 --- singleapplication_p.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index 1a061f2..6702b94 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -503,12 +503,14 @@ void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quin if ( !isFrameComplete( dataSocket ) ) return; - Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() ); + const QByteArray message = dataSocket->readAll(); writeAck( dataSocket ); ConnectionInfo &info = connectionMap[dataSocket]; info.stage = StageConnectedHeader; + + Q_EMIT q->receivedMessage( instanceId, message); } void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId ) -- cgit v1.2.1