Commit c3c30113 authored by Bernd Buschinski's avatar Bernd Buschinski

Fix memleaks in duchain unittests

Summary:
The TypeSystem::create test was changed as now the destruction is also taken into account for QBENCHMARK

The TopDUContext dtor is protected, however you can execute
delete TopDUContext; but it will NOT call the protected TopDUContext dtor but the public DUContext dtor.

Test Plan:
- compile kdevelop unitest with ASAN&LSAN
- execute test_duchain

Reviewers: #kdevelop, kfunk

Reviewed By: #kdevelop, kfunk

Subscribers: kfunk, kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D16458
parent 0fc8dddf
......@@ -921,7 +921,7 @@ void TestDUChain::benchTypeRegistry()
IntegralTypeData data;
data.m_dataType = IntegralType::TypeInt;
data.typeClassId = IntegralType::Identity;
data.inRepository = false;
data.inRepository = true;
data.m_modifiers = 42;
data.m_dynamic = false;
data.refCount = 1;
......@@ -938,9 +938,10 @@ void TestDUChain::benchTypeRegistry()
case 1:
TypeSystem::self().dynamicSize(data);
break;
case 2:
TypeSystem::self().create(&data);
case 2: {
AbstractType::Ptr t(TypeSystem::self().create(&data));
break;
}
case 3:
TypeSystem::self().isFactoryLoaded(data);
break;
......@@ -1014,7 +1015,9 @@ void TestDUChain::benchDeclarationQualifiedIdentifier()
QVector<DUContext*> contexts;
contexts.reserve(10);
DUChainWriteLocker lock;
contexts << new TopDUContext(IndexedString("/tmp/something"), {0, 0, INT_MAX, INT_MAX});
auto topDUContext = new TopDUContext(IndexedString("/tmp/something"), {0, 0, INT_MAX, INT_MAX});
DUChain::self()->addDocumentChain(topDUContext);
contexts << topDUContext;
for (int i = 1; i < contexts.capacity(); ++i) {
contexts << new DUContext({0, 0, INT_MAX, INT_MAX}, contexts.at(i-1));
contexts.last()->setLocalScopeIdentifier(QualifiedIdentifier(QString::number(i)));
......@@ -1028,6 +1031,10 @@ void TestDUChain::benchDeclarationQualifiedIdentifier()
count += dec->qualifiedIdentifier().count();
}
QVERIFY(count > 0);
// manually delete as QScopedPointer does not work well with QBENCHMARK
delete dec;
DUChain::self()->removeDocumentChain(topDUContext);
}
#include "test_duchain.moc"
......
Markdown is supported
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