Commit c2c92eb9 authored by David Faure's avatar David Faure
Browse files

Fix memory leak of ItemRetrievalJobFactory in ItemRetrievalManager

Summary:
It was never deleted. Fixed by making the ItemRetrievalManager own
the ItemRetrievalJobFactory in all cases.

Test Plan: ctest -R AkonadiServer-itemretrievertest in an ASAN build

Reviewers: dvratil

Reviewed By: dvratil

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D21120
parent ec9d24cf
......@@ -300,8 +300,8 @@ private Q_SLOTS:
// Setup
for (int step = 0; step < 2; ++step) {
DbInitializer dbInitializer;
FakeItemRetrievalJobFactory factory(dbInitializer);
ItemRetrievalManager mgr(&factory);
auto *factory = new FakeItemRetrievalJobFactory(dbInitializer);
ItemRetrievalManager mgr{std::unique_ptr<AbstractItemRetrievalJobFactory>(factory)};
QTest::qWait(100);
// Given a PimItem with existing parts
......@@ -315,7 +315,7 @@ private Q_SLOTS:
}
Q_FOREACH (const auto &availablePart, availableParts) {
factory.addJobResult(item.id(), availablePart.first, availablePart.second);
factory->addJobResult(item.id(), availablePart.first, availablePart.second);
}
if (step == 0) {
......@@ -333,7 +333,7 @@ private Q_SLOTS:
}
// Check that the factory had exactly one retrieval job
QCOMPARE(factory.jobsCount(), expectedRetrievalJobs);
QCOMPARE(factory->jobsCount(), expectedRetrievalJobs);
} else {
QVector<ClientThread *> threads;
......
......@@ -46,13 +46,13 @@ class ItemRetrievalJobFactory : public AbstractItemRetrievalJobFactory
};
ItemRetrievalManager::ItemRetrievalManager(QObject *parent)
: ItemRetrievalManager(new ItemRetrievalJobFactory, parent)
: ItemRetrievalManager(std::make_unique<ItemRetrievalJobFactory>(), parent)
{
}
ItemRetrievalManager::ItemRetrievalManager(AbstractItemRetrievalJobFactory *factory, QObject *parent)
ItemRetrievalManager::ItemRetrievalManager(std::unique_ptr<AbstractItemRetrievalJobFactory> factory, QObject *parent)
: AkThread(QStringLiteral("ItemRetrievalManager"), QThread::HighPriority, parent)
, mJobFactory(factory)
, mJobFactory(std::move(factory))
{
qDBusRegisterMetaType<QByteArrayList>();
......
......@@ -55,7 +55,7 @@ class ItemRetrievalManager : public AkThread
Q_OBJECT
public:
explicit ItemRetrievalManager(QObject *parent = nullptr);
explicit ItemRetrievalManager(AbstractItemRetrievalJobFactory *factory, QObject *parent = nullptr);
explicit ItemRetrievalManager(std::unique_ptr<AbstractItemRetrievalJobFactory> factory, QObject *parent = nullptr);
~ItemRetrievalManager() override;
/**
......@@ -85,7 +85,7 @@ private Q_SLOTS:
protected:
static ItemRetrievalManager *sInstance;
AbstractItemRetrievalJobFactory *mJobFactory = nullptr;
std::unique_ptr<AbstractItemRetrievalJobFactory> mJobFactory;
/// Protects mPendingRequests and every Request object posted to it
QReadWriteLock *mLock = nullptr;
......
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