aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-11-24 05:30:41 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-11-24 09:01:39 +0100
commit3650975e566d13483869d1213e434a1ce609335b (patch)
tree1549614660c337f9ba979326379d12c39c85aeb6
parentMerge pull request #140 from itay-grudev/itay-grudev-patch-1 (diff)
downloadsingleapplication-3650975e566d13483869d1213e434a1ce609335b.tar.xz
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
-rw-r--r--singleapplication_p.cpp4
1 files changed, 3 insertions, 1 deletions
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 )