-
-
Notifications
You must be signed in to change notification settings - Fork 236
Description
The SingleApplication constructor explicitly attaches itself to the shared memory and deletes the object QSharedMemory afterwards. This is to make sure that a 'dangling' shared memory which is not referenced anymore (due to a crashed application) is freed in the destructor.
I suggest to check the return value and the possible error when trying to attach, something like
d->memory->attach();
{
switch(d->memory->error())
{
case QSharedMemory::NoError: // successfully attached, resource was already created
d->memory->detach(); // should release the resource
break;
case QSharedMemory::NotFound: // resource is not available yet
break;
default:
abortSafely(); // report error message
}
}
Background: We had the problem that our application didn't start anymore on the build server (Mac). The error message was
SingleApplication: Unable to create block.
SingleApplication: 7 "QSharedMemory::create: out of resources"
which is the message created when d->memory->create( sizeof( InstancesInfo ) ) fails. Unfortunately, we did not check the system resources with ipcs before rebooting the server.
After spending some time in the Qt documentation and the code base, I came to the conclusion that maybe already the attach() failed.
Because the memory itself is not a problem, I assume that the internal QSystemSemaphore of the QSharedMemory could not be acquired.