Commit 66b24c88 authored by David Faure's avatar David Faure
Browse files

Fix memory leak due to getTestMonitor()

Summary:
asan build said the Monitor was leaked, and it was indeed.
Fixed using std::unique_ptr.

Test Plan:
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DECM_ENABLE_SANITIZERS="address" -DCMAKE_CXX_FLAGS='-stdlib=libc++' -DCMAKE_SHARED_LINKER_FLAGS='-stdlib=libc++' -DCMAKE_EXE_LINKER_FLAGS='-stdlib=libc++' .. && make && ctest
(with an asan build of Qt)

Reviewers: dvratil

Reviewed By: dvratil

Subscribers: kde-pim

Differential Revision: https://phabricator.kde.org/D21093
parent 24b0e5a6
......@@ -40,7 +40,7 @@ private Q_SLOTS:
void testCreateCollection()
{
auto monitor = getTestMonitor();
QSignalSpy spy(monitor, &Monitor::collectionAdded);
QSignalSpy spy(monitor.get(), &Monitor::collectionAdded);
Collection col;
col.setName(QLatin1String("test_collection"));
......
......@@ -59,7 +59,7 @@ private Q_SLOTS:
void testDelete()
{
auto monitor = getTestMonitor();
QSignalSpy spy(monitor, &Monitor::itemsRemoved);
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
ItemFetchJob *fjob = new ItemFetchJob(Item(1), this);
AKVERIFYEXEC(fjob);
......@@ -81,7 +81,7 @@ private Q_SLOTS:
void testDeleteFromUnselectedCollection()
{
auto monitor = getTestMonitor();
QSignalSpy spy(monitor, &Monitor::itemsRemoved);
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
const QString path = QStringLiteral("res1") +
CollectionPathResolver::pathDelimiter() +
......@@ -115,7 +115,7 @@ private Q_SLOTS:
void testRidDelete()
{
auto monitor = getTestMonitor();
QSignalSpy spy(monitor, &Monitor::itemsRemoved);
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
{
ResourceSelectJob *select = new ResourceSelectJob(QStringLiteral("akonadi_knut_resource_0"));
......@@ -154,7 +154,7 @@ private Q_SLOTS:
void testTagDelete()
{
auto monitor = getTestMonitor();
QSignalSpy spy(monitor, &Monitor::itemsRemoved);
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
// Create tag
Tag tag;
......@@ -198,7 +198,7 @@ private Q_SLOTS:
void testCollectionDelete()
{
auto monitor = getTestMonitor();
QSignalSpy spy(monitor, &Monitor::itemsRemoved);
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
const Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
ItemFetchJob *fjob = new ItemFetchJob(col, this);
......
......@@ -144,17 +144,17 @@ private Q_SLOTS:
QEXPECT_FAIL("", "Check not yet implemented by the server.", Continue);
QVERIFY(!store->exec());
Monitor *monitor = getTestMonitor();
QSignalSpy itemMovedSpy(monitor, &Monitor::itemsMoved);
auto monitor = getTestMonitor();
QSignalSpy itemMovedSpy(monitor.get(), &Monitor::itemsMoved);
// Wait for the notifciation so that it does not disturb the next test
QTRY_COMPARE(itemMovedSpy.count(), 1);
}
void testMoveNotifications()
{
Monitor *monitor = getTestMonitor();
QSignalSpy itemMovedSpy(monitor, &Monitor::itemsMoved);
QSignalSpy itemAddedSpy(monitor, &Monitor::itemAdded);
auto monitor = getTestMonitor();
QSignalSpy itemMovedSpy(monitor.get(), &Monitor::itemsMoved);
QSignalSpy itemAddedSpy(monitor.get(), &Monitor::itemAdded);
Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
Item item(QStringLiteral("application/octet-stream"));
......
......@@ -97,7 +97,7 @@ bool trackAkonadiProcess(bool track)
}
}
Akonadi::Monitor *getTestMonitor()
std::unique_ptr<Akonadi::Monitor> getTestMonitor()
{
auto m = new Akonadi::Monitor();
m->fetchCollection(true);
......@@ -111,7 +111,7 @@ Akonadi::Monitor *getTestMonitor()
QSignalSpy readySpy(m, &Akonadi::Monitor::monitorReady);
readySpy.wait();
return m;
return std::unique_ptr<Akonadi::Monitor>(m);
}
#endif
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