aboutsummaryrefslogtreecommitdiff
path: root/singleapplication.cpp
diff options
context:
space:
mode:
authorItay Grudev <itay@grudev.com>2016-05-04 20:41:23 +0100
committerItay Grudev <itay@grudev.com>2016-05-04 20:41:23 +0100
commit8bccf446e190aedf0ffe11772a6a73d469ce774a (patch)
treea40fa9e229af6d7e6d789d5e451e0bc6ff11dd8c /singleapplication.cpp
parentUpdated documentation (diff)
downloadsingleapplication-8bccf446e190aedf0ffe11772a6a73d469ce774a.tar.xz
Improved restoring QSharedMemory after crash
Diffstat (limited to 'singleapplication.cpp')
-rw-r--r--singleapplication.cpp11
1 files 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()
{