Commit 50de4e84 authored by Igor Kushnir's avatar Igor Kushnir Committed by Milian Wolff
Browse files

ItemRepositoryRegistry: don't access uninitialized d-pointer

My recent commit "Eliminate ItemRepositoryRegistryPrivate::open()"
moved code from ItemRepositoryRegistryPrivate::open() into
ItemRepositoryRegistryPrivate's constructor. ItemRepositoryRegistry's
d-pointer is not initialized during its ItemRepositoryRegistryPrivate's
construction, and so must not be referenced.

Move code from ItemRepositoryRegistry::customCounter() into a new
function ItemRepositoryRegistryPrivate::customCounter(); call the new
function from the old one and from ItemRepositoryRegistryPrivate's ctor.

This fixes the following segmentation fault at KDevelop start:
QMap<QString, QAtomicInt*>::detach() (this=0x563b5bc08) at /usr/include/qt/QtCore/qmap.h:361
QMap<QString, QAtomicInt*>::find(QString const&) (this=0x563b5bc08, akey=...) at /usr/include/qt/QtCore/qmap.h:865
KDevelop::ItemRepositoryRegistry::customCounter(QString const&, int) (this=0x563b5bbc8700, identity=..., initialValue=0) at .../kdevelop/kdevplatform/serialization/itemrepositoryregistry.cpp:174
KDevelop::ItemRepositoryRegistryPrivate::ItemRepositoryRegistryPrivate(KDevelop::ItemRepositoryRegistry&, QString const&) (this=0x563b5bbc8720, owner=..., path=...) at .../kdevelop/kdevplatform/serialization/itemrepositoryregistry.cpp:288
KDevelop::ItemRepositoryRegistry::ItemRepositoryRegistry(QString const&) (this=0x563b5bbc8700, repositoryPath=...) at .../kdevelop/kdevplatform/serialization/itemrepositoryregistry.cpp:128
KDevelop::ItemRepositoryRegistry::initialize(QString const&) (repositoryPath=...) at .../kdevelop/kdevplatform/serialization/itemrepositoryregistry.cpp:137
KDevelop::DUChain::initialize() () at .../kdevelop/kdevplatform/language/duchain/duchain.cpp:1284
KDevelop::CorePrivate::initialize(KDevelop::Core::Setup, QString const&) (this=0x563b5b187800, mode=KDevelop::Core::Default, session=...) at .../kdevelop/kdevplatform/shell/core.cpp:196
KDevelop::Core::initialize(KDevelop::Core::Setup, QString const&) (mode=KDevelop::Core::Default, session=...) at .../kdevelop/kdevplatform/shell/core.cpp:286
main(int, char**) (argc=3, argv=0x7fff678463b8) at .../kdevelop/app/main.cpp:752
parent 15f1d789
......@@ -114,8 +114,9 @@ public:
/// @param path A shared directory-path that the item-repositories are to be loaded from.
/// @note Currently the given path must reference a hidden directory, just to make sure we're
/// not accidentally deleting something important.
explicit ItemRepositoryRegistryPrivate(ItemRepositoryRegistry& owner, const QString& path);
explicit ItemRepositoryRegistryPrivate(const QString& path);
QAtomicInt& customCounter(const QString& identity, int initialValue);
void lockForWriting();
void unlockForWriting();
void deleteDataDirectory(bool recreate = true);
......@@ -125,7 +126,7 @@ public:
ItemRepositoryRegistry* ItemRepositoryRegistry::m_self = nullptr;
ItemRepositoryRegistry::ItemRepositoryRegistry(const QString& repositoryPath)
: d_ptr(new ItemRepositoryRegistryPrivate(*this, repositoryPath))
: d_ptr(new ItemRepositoryRegistryPrivate(repositoryPath))
{
}
......@@ -167,15 +168,20 @@ QRecursiveMutex& ItemRepositoryRegistry::mutex()
return d->m_mutex;
}
QAtomicInt& ItemRepositoryRegistryPrivate::customCounter(const QString& identity, int initialValue)
{
auto customCounterIt = m_customCounters.find(identity);
if (customCounterIt == m_customCounters.end()) {
customCounterIt = m_customCounters.insert(identity, new QAtomicInt(initialValue));
}
return **customCounterIt;
}
QAtomicInt& ItemRepositoryRegistry::customCounter(const QString& identity, int initialValue)
{
Q_D(ItemRepositoryRegistry);
auto customCounterIt = d->m_customCounters.find(identity);
if (customCounterIt == d->m_customCounters.end()) {
customCounterIt = d->m_customCounters.insert(identity, new QAtomicInt(initialValue));
}
return **customCounterIt;
return d->customCounter(identity, initialValue);
}
///The global item-repository registry that is used by default
......@@ -262,7 +268,7 @@ void ItemRepositoryRegistryPrivate::deleteDataDirectory(bool recreate)
}
}
ItemRepositoryRegistryPrivate::ItemRepositoryRegistryPrivate(ItemRepositoryRegistry& owner, const QString& path)
ItemRepositoryRegistryPrivate::ItemRepositoryRegistryPrivate(const QString& path)
: m_path(path)
{
Q_ASSERT(!path.isEmpty());
......@@ -285,7 +291,7 @@ ItemRepositoryRegistryPrivate::ItemRepositoryRegistryPrivate(ItemRepositoryRegis
stream >> counterName;
int counterValue;
stream >> counterValue;
owner.customCounter(counterName, 0) = counterValue;
customCounter(counterName, 0) = counterValue;
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment