From 07e187d4d8ccbe31130db7b77d1bce217b33809a Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Wed, 24 Nov 2021 05:21:30 +0100
Subject: [PATCH] Fix crash in SingleApplication when other end exits
 immediately

In those cases the emit might cause the server to remove the connection
and we are working with a dangling pointer. We can't call putChar on
that, so acknowledge the message immediately and then emit the message.
---
 third_party/SingleApplication-3.3.0/singleapplication_p.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/third_party/SingleApplication-3.3.0/singleapplication_p.cpp b/third_party/SingleApplication-3.3.0/singleapplication_p.cpp
index 133972825..3b6f96fe7 100644
--- a/third_party/SingleApplication-3.3.0/singleapplication_p.cpp
+++ b/third_party/SingleApplication-3.3.0/singleapplication_p.cpp
@@ -494,12 +494,12 @@ void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quin
     if ( !isFrameComplete( dataSocket ) )
         return;
 
-    Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() );
-
     writeAck( dataSocket );
 
     ConnectionInfo &info = connectionMap[dataSocket];
     info.stage = StageConnectedHeader;
+
+    Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
 }
 
 void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId )
-- 
GitLab