From 7595c7e697e465bbdd2e7212b8f565db49d6f451 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 2 Mar 2015 14:09:01 +0100 Subject: [PATCH] Discovery: Free some memory on VIO dir close (#2902) --- src/libsync/discoveryphase.cpp | 13 ++++++++++++- src/libsync/discoveryphase.h | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 91b5bb5c1..9060a2bc5 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -309,6 +309,15 @@ void DiscoveryMainThread::setupHooks(DiscoveryJob *discoveryJob, const QString & connect(discoveryJob, SIGNAL(doOpendirSignal(QString,DiscoveryDirectoryResult*)), this, SLOT(doOpendirSlot(QString,DiscoveryDirectoryResult*)), Qt::QueuedConnection); + connect(discoveryJob, SIGNAL(doClosedirSignal(QString)), + this, SLOT(doClosedirSlot(QString)), + Qt::QueuedConnection); +} + +void DiscoveryMainThread::doClosedirSlot(QString path) +{ + //qDebug() << Q_FUNC_INFO << "Invalidating" << path; + deleteCacheEntry(path); } // Coming from owncloud_opendir -> DiscoveryJob::vio_opendir_hook -> doOpendirSignal @@ -461,9 +470,11 @@ void DiscoveryJob::remote_vio_closedir_hook (csync_vio_handle_t *dhandle, void { DiscoveryJob *discoveryJob = static_cast(userdata); if (discoveryJob) { - qDebug() << Q_FUNC_INFO << discoveryJob; DiscoveryDirectoryResult *directoryResult = static_cast (dhandle); + QString path = directoryResult->path; + qDebug() << Q_FUNC_INFO << discoveryJob << path; delete directoryResult; // just deletes the struct and the iterator, the data itself is owned by the SyncEngine/DiscoveryMainThread + emit discoveryJob->doClosedirSignal(path); } } diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index 207883ccf..a4ce8482d 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -87,7 +87,16 @@ public: DiscoveryMainThread(AccountPtr account) : QObject(), _account(account), _currentDiscoveryDirectoryResult(0) { } + void deleteCacheEntry(QString path) { + //qDebug() << path << _directoryContents.value(path).count(); + foreach (csync_vio_file_stat_t* stat, _directoryContents.value(path)) { + csync_vio_file_stat_destroy(stat); + } + _directoryContents.remove(path); + } + ~DiscoveryMainThread() { + // Delete the _contents_ of the list-map explicitly: foreach (const QLinkedList & list, _directoryContents) { foreach (csync_vio_file_stat_t* stat, list) { csync_vio_file_stat_destroy(stat); @@ -100,6 +109,7 @@ public: public slots: // From DiscoveryJob: void doOpendirSlot(QString url, DiscoveryDirectoryResult* ); + void doClosedirSlot(QString path); // From Job: void singleDirectoryJobResultSlot(QLinkedList); @@ -164,6 +174,8 @@ signals: // After the discovery job has been woken up again (_vioWaitCondition) void doOpendirSignal(QString url, DiscoveryDirectoryResult*); + // to tell the main thread to invalidate its directory data + void doClosedirSignal(QString path); }; }