QNetworkAccessManager: delete the httpThread
authorMartin Petersson <Martin.Petersson@nokia.com>
Wed, 13 Jun 2012 06:59:35 +0000 (08:59 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 20 Jun 2012 13:45:07 +0000 (15:45 +0200)
The httpThread was using deleteLater the finished signal of the
thread to call the deleteLater slot. If the QNetworkAccessManager is
deleted when the application is closed then then fished is emitted
but we never return to the eventloop so the deletion is never done.

This will delete the httpThread directly instead of using deleteLater

Task-number: QTBUG-25487
Change-Id: I1fdbd4eca01e8bd8b3a98936298e5c78217752b4
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
src/network/access/qnetworkaccessmanager.cpp
src/network/access/qnetworkreplyhttpimpl.cpp

index f83dc4f..d5b4eec 100644 (file)
@@ -1280,9 +1280,12 @@ void QNetworkAccessManagerPrivate::clearCache(QNetworkAccessManager *manager)
     manager->d_func()->authenticationManager->clearCache();
 
     if (manager->d_func()->httpThread) {
-        // The thread will deleteLater() itself from its finished() signal
         manager->d_func()->httpThread->quit();
         manager->d_func()->httpThread->wait(5000);
+        if (manager->d_func()->httpThread->isFinished())
+            delete manager->d_func()->httpThread;
+        else
+            QObject::connect(manager->d_func()->httpThread, SIGNAL(finished()), manager->d_func()->httpThread, SLOT(deleteLater()));
         manager->d_func()->httpThread = 0;
     }
 }
@@ -1290,9 +1293,12 @@ void QNetworkAccessManagerPrivate::clearCache(QNetworkAccessManager *manager)
 QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate()
 {
     if (httpThread) {
-        // The thread will deleteLater() itself from its finished() signal
         httpThread->quit();
         httpThread->wait(5000);
+        if (httpThread->isFinished())
+            delete httpThread;
+        else
+            QObject::connect(httpThread, SIGNAL(finished()), httpThread, SLOT(deleteLater()));
         httpThread = 0;
     }
 }
index e1ec9a9..3e92126 100644 (file)
@@ -620,7 +620,6 @@ void QNetworkReplyHttpImplPrivate::postRequest()
         // At some point we could switch to having multiple threads if it makes sense.
         managerPrivate->httpThread = new QThread();
         managerPrivate->httpThread->setObjectName(QStringLiteral("httpThread"));
-        QObject::connect(managerPrivate->httpThread, SIGNAL(finished()), managerPrivate->httpThread, SLOT(deleteLater()));
         managerPrivate->httpThread->start();
 
         thread = managerPrivate->httpThread;
@@ -917,9 +916,12 @@ void QNetworkReplyHttpImplPrivate::postRequest()
             replyDownloadData(delegate->synchronousDownloadData);
         }
 
-        // End the thread. It will delete itself from the finished() signal
         thread->quit();
         thread->wait(5000);
+        if (thread->isFinished())
+            delete thread;
+        else
+            QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
 
         finished();
     } else {