QmlPuppet: Don't crash when failing to lock shared memory

Obviously, you cannot set m_sharedMemory to 0 and then write the error
and errorString to it.

Change-Id: Ifcacfd7adcb4ff2fd88ebda21aa81094337233f6
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Ulf Hermann
2016-09-15 16:02:22 +02:00
committed by Tim Jenssen
parent b259939755
commit 7dab165c3b
@@ -65,23 +65,19 @@ public:
m_sharedMemory->unlock();
}
bool lock()
{
if (m_sharedMemory && m_sharedMemory->lock())
bool tryLocker(const QString &function) {
if (!m_sharedMemory)
return false;
if (m_sharedMemory->lock())
return true;
m_sharedMemory->m_errorString = QStringLiteral("%1: unable to lock").arg(function);
m_sharedMemory->m_error = QSharedMemory::LockError;
m_sharedMemory = 0;
return false;
}
bool tryLocker(const QString function) {
if (!lock()) {
m_sharedMemory->m_errorString = QStringLiteral("%1: unable to lock").arg(function);
m_sharedMemory->m_error = QSharedMemory::LockError;
return false;
}
return true;
}
private:
SharedMemory *m_sharedMemory;
};