Attempt to fix the Account::slotHandleSslErrors crash
authorJocelyn Turcotte <jturcotte@woboq.com>
Wed, 15 Jun 2016 16:05:56 +0000 (18:05 +0200)
committerJocelyn Turcotte <jturcotte@woboq.com>
Wed, 15 Jun 2016 16:12:02 +0000 (18:12 +0200)
Events from the crash reporter suggest that the QNAM and its
child replies might get deleted before returning from this method
and the only possible cause we can see is that the inner event
loop has something to do with it.

Try keeping a ref on the QNAM while in this method to make sure
that it won't get deleted by the inner event loop.

src/libsync/account.cpp

index 24c578305e1af624ceac219af4857e15a6648d91..99b1d5f92baf04b3af350628e2d90744b49daa59 100644 (file)
@@ -427,6 +427,12 @@ void Account::slotHandleSslErrors(QNetworkReply *reply , QList<QSslError> errors
         return;
     }
 
+    // SslDialogErrorHandler::handleErrors will run an event loop that might execute
+    // the deleteLater() of the QNAM before we have the chance of unwinding our stack.
+    // Keep a ref here on our stackframe to make sure that it doesn't get deleted before
+    // handleErrors returns.
+    QSharedPointer<QNetworkAccessManager> qnamLock = _am;
+
     if (_sslErrorHandler->handleErrors(errors, reply->sslConfiguration(), &approvedCerts, sharedFromThis())) {
         QSslSocket::addDefaultCaCertificates(approvedCerts);
         addApprovedCerts(approvedCerts);