Improved restoring QSharedMemory after crash

This commit is contained in:
Itay Grudev 2016-05-04 20:41:23 +01:00
parent 8c9327036e
commit 8bccf446e1

View File

@ -185,7 +185,12 @@ SingleApplication::SingleApplication(int &argc, char *argv[], uint8_t secondaryI
QString serverName = app_t::organizationName() + app_t::applicationName(); QString serverName = app_t::organizationName() + app_t::applicationName();
serverName.replace( QRegExp("[^\\w\\-. ]"), "" ); serverName.replace( QRegExp("[^\\w\\-. ]"), "" );
// Guarantee thread safe behaviour with a shared memory block // 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 ); d->memory = new QSharedMemory( serverName );
// Create a shared memory block with a minimum size of 1 byte // Create a shared memory block with a minimum size of 1 byte
@ -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() void SingleApplication::slotConnectionEstablished()
{ {