kdecore: fix runtime assert about accessing global static after its destruction

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-10-23 12:37:06 +03:00
parent 47c8c442c2
commit 614568e372

View file

@ -22,6 +22,7 @@
#include "kdebug.h"
#include "kde_file.h"
#include <QStandardPaths>
#include <QCoreApplication>
#include <QThread>
@ -50,7 +51,10 @@ KLockFilePrivate::KLockFilePrivate()
KLockFile::KLockFile(const QString &file)
: d(new KLockFilePrivate())
{
d->m_lockfile = QFile::encodeName(KGlobal::dirs()->saveLocation("tmp"));
// NOTE: KConfig may attempt to create KLockFile from its destructor when KGlobal is no more
// thus QStandardPaths::writableLocation() is used here
d->m_lockfile = QFile::encodeName(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation));
d->m_lockfile.append('/');
d->m_lockfile.append(QByteArray::number(qHash(file)));
d->m_lockfile.append(".klockfile");
}