FolderStatusModel: Fix crash when there is an error while expanding folders
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 31 May 2018 09:00:11 +0000 (11:00 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:57:55 +0000 (10:57 +0100)
In FolderStatusModel::slotLscolFinishedWithError, the call to parentInfo->resetSubs
deleted the 'job' and the reply 'r' which we accessed later to get the error code.

Fix this problem twice by
 1) Get the error code before caling resetSubs
 2) in FolderStatusModel::SubFolderInfo::resetSubs, call deleteLater instead of delete

Regression introduced in commit d69936e0

Issue #6562

src/gui/folderstatusmodel.cpp

index e9f6974c82660eb39b67c6db59677c973f912d3b..3db8eda894337b0237bfdbe3bb314d2d5e415558 100644 (file)
@@ -760,10 +760,11 @@ void FolderStatusModel::slotLscolFinishedWithError(QNetworkReply *r)
     if (parentInfo) {
         qCDebug(lcFolderStatus) << r->errorString();
         parentInfo->_lastErrorString = r->errorString();
+        auto error = r->error();
 
         parentInfo->resetSubs(this, idx);
 
-        if (r->error() == QNetworkReply::ContentNotFoundError) {
+        if (error == QNetworkReply::ContentNotFoundError) {
             parentInfo->_fetched = true;
         } else {
             ASSERT(!parentInfo->hasLabel());
@@ -1241,7 +1242,11 @@ bool FolderStatusModel::SubFolderInfo::hasLabel() const
 void FolderStatusModel::SubFolderInfo::resetSubs(FolderStatusModel *model, QModelIndex index)
 {
     _fetched = false;
-    _fetchingJob->deleteLater();
+    if (_fetchingJob) {
+        disconnect(_fetchingJob, nullptr, model, nullptr);
+        _fetchingJob->deleteLater();
+        _fetchingJob.clear();
+    }
     if (hasLabel()) {
         model->beginRemoveRows(index, 0, 0);
         _fetchingLabel = false;