summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2016-04-03 18:36:52 +0200
committerDavid Faure <david.faure@kdab.com>2016-04-10 07:37:51 +0000
commitb6eea89b67e0d3bb4f8f888fff21257eff0b65a5 (patch)
tree51818a84b2bdc53eabc821f7f7c7ca218b2e0489
parent8c427e5bdfcb54e19d10646d9ff45674077253c9 (diff)
Fix crash when using QLockFile in a global destructor
(for instance any global object which writes out to a config file in the destructor). If the global cache isn't available anymore, don't use it. Change-Id: I851a6e394d0b073aebf3ffd88b1966d424bfb92e Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--src/corelib/io/qlockfile_unix.cpp2
-rw-r--r--tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp10
2 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp
index 623968b869..bcef84206e 100644
--- a/src/corelib/io/qlockfile_unix.cpp
+++ b/src/corelib/io/qlockfile_unix.cpp
@@ -136,6 +136,8 @@ static QBasicMutex fcntlLock;
static bool fcntlWorksAfterFlock(const QString &fn)
{
QMutexLocker lock(&fcntlLock);
+ if (fcntlOK.isDestroyed())
+ return QLockFilePrivate::checkFcntlWorksAfterFlock(fn);
bool *worksPtr = fcntlOK->object(fn);
if (!worksPtr) {
worksPtr = new bool(QLockFilePrivate::checkFcntlWorksAfterFlock(fn));
diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
index 21c5696d1d..4884c126d4 100644
--- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
+++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
@@ -546,5 +546,15 @@ bool tst_QLockFile::overwritePidInLockFile(const QString &filePath, qint64 pid)
return f.write(buf) == buf.size();
}
+struct LockFileUsageInGlobalDtor
+{
+ ~LockFileUsageInGlobalDtor() {
+ QLockFile lockFile(QDir::currentPath() + "/lastlock");
+ QVERIFY(lockFile.lock());
+ QVERIFY(lockFile.isLocked());
+ }
+};
+LockFileUsageInGlobalDtor s_instance;
+
QTEST_MAIN(tst_QLockFile)
#include "tst_qlockfile.moc"