From 8bccf446e190aedf0ffe11772a6a73d469ce774a Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Wed, 4 May 2016 20:41:23 +0100 Subject: Improved restoring QSharedMemory after crash --- singleapplication.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/singleapplication.cpp b/singleapplication.cpp index bd0b2b4..c5f52dc 100644 --- a/singleapplication.cpp +++ b/singleapplication.cpp @@ -185,8 +185,13 @@ SingleApplication::SingleApplication(int &argc, char *argv[], uint8_t secondaryI QString serverName = app_t::organizationName() + app_t::applicationName(); serverName.replace( QRegExp("[^\\w\\-. ]"), "" ); - // Guarantee thread safe behaviour with a shared memory block - d->memory = new QSharedMemory(serverName); + // Guarantee thread safe behaviour with a shared memory block. Also by + // attaching to it and deleting it we make sure that the memory i deleted + // even if the process had crashed + d->memory = new QSharedMemory( serverName ); + d->memory->attach(); + delete d->memory; + d->memory = new QSharedMemory( serverName ); // Create a shared memory block with a minimum size of 1 byte #ifdef Q_OS_UNIX @@ -246,7 +251,7 @@ bool SingleApplication::isSecondary() } /** - * @brief Executed when the showUp command is sent to LocalServer + * @brief Executed when a connection has been made to the LocalServer */ void SingleApplication::slotConnectionEstablished() { -- cgit v1.2.1