Account: Fix crash when deleting an account
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 22 Nov 2018 07:46:33 +0000 (08:46 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:21 +0000 (10:58 +0100)
We should not have request parented to the account, otherwise we might get
a loop on the deletion order.

Issue #6893

src/libsync/abstractnetworkjob.cpp
src/libsync/account.cpp

index 7365c97a382ef3cb282e9b2818c0a2022ca71780..e44af32a74eb9a52433b7dbf5c231a20fabe151a 100644 (file)
@@ -54,6 +54,9 @@ AbstractNetworkJob::AbstractNetworkJob(AccountPtr account, const QString &path,
     , _reply(nullptr)
     , _path(path)
 {
+    // Since we hold a QSharedPointer to the account, this makes no sense. (issue #6893)
+    ASSERT(account != parent);
+
     _timer.setSingleShot(true);
     _timer.setInterval((httpTimeout ? httpTimeout : 300) * 1000); // default to 5 minutes.
     connect(&_timer, &QTimer::timeout, this, &AbstractNetworkJob::slotTimeout);
index f9a856b6379eb75dc8fec1568a2e69f4d41fbff5..cde76ceb5911d678d2290b9b86e0faa77e39d2c1 100644 (file)
@@ -294,7 +294,7 @@ QNetworkReply *Account::sendRawRequest(const QByteArray &verb, const QUrl &url,
 
 SimpleNetworkJob *Account::sendRequest(const QByteArray &verb, const QUrl &url, QNetworkRequest req, QIODevice *data)
 {
-    auto job = new SimpleNetworkJob(sharedFromThis(), this);
+    auto job = new SimpleNetworkJob(sharedFromThis());
     job->startRequest(verb, url, req, data);
     return job;
 }
@@ -621,7 +621,7 @@ void Account::fetchDirectEditors(const QUrl &directEditingURL, const QString &di
     if (!directEditingURL.isEmpty() &&
         (directEditingETag.isEmpty() || directEditingETag != _lastDirectEditingETag)) {
             // Fetch the available editors and their mime types
-            auto *job = new JsonApiJob(sharedFromThis(), QLatin1String("ocs/v2.php/apps/files/api/v1/directEditing"), this);
+            auto *job = new JsonApiJob(sharedFromThis(), QLatin1String("ocs/v2.php/apps/files/api/v1/directEditing"));
             QObject::connect(job, &JsonApiJob::jsonReceived, this, &Account::slotDirectEditingRecieved);
             job->start();
     }