Fix segfault with onlinepollerthread
authorTorste Aikio <zokier@zokier.laptop>
Tue, 6 Jul 2010 12:10:08 +0000 (15:10 +0300)
committerTorste Aikio <zokier@zokier.laptop>
Tue, 6 Jul 2010 12:10:08 +0000 (15:10 +0300)
src/onlinepollerthread.cpp
src/onlinepollerthread.h
src/selectremotedlg.cpp

index 73b3fd5..89cc31a 100644 (file)
@@ -5,6 +5,7 @@
 
 void OnlinePollerThread::run()
 {
+    running = true;
     QTM_PREPEND_NAMESPACE(QNetworkConfigurationManager) qncm;
     if (!qncm.isOnline()) {
         QDBusMessage m = QDBusMessage::createMethodCall(
@@ -12,12 +13,21 @@ void OnlinePollerThread::run()
                 "com.nokia.icd_ui", "show_conn_dlg");
         m << false;
         QDBusConnection::systemBus().send(m);
-        while(!qncm.isOnline())
+        while(running)
         {
-            msleep(250);
+            if (!qncm.isOnline()) {
+                msleep(250);
+            } else {
+                break;
+            }
         }
     }
     emit online();
     exec();
 }
 
+void OnlinePollerThread::stop()
+{
+    running = false;
+}
+
index 11c1fe6..9c4c521 100644 (file)
@@ -12,6 +12,12 @@ public:
 
 signals:
     void online();
+
+public:
+    void stop();
+
+private:
+    bool running;
 };
 
 #endif //ONLINEPOLLERTHREAD_H
index ec435c6..8b1085e 100644 (file)
@@ -18,6 +18,7 @@
 SelectRemoteDlg::SelectRemoteDlg(QWidget *parent)
     : QDialog(parent)
 {
+    onlinePollerThread = NULL;
     this->setWindowTitle(tr("Select remote"));
     this->setMinimumHeight(320);
 
@@ -55,7 +56,8 @@ SelectRemoteDlg::~SelectRemoteDlg()
 {
     delete layout;
     if (onlinePollerThread != NULL) {
-        onlinePollerThread->quit();
+        onlinePollerThread->stop();
+        onlinePollerThread->wait();
         delete onlinePollerThread;
         onlinePollerThread = NULL;
     }
@@ -117,7 +119,8 @@ void SelectRemoteDlg::downloadRemote()
 void SelectRemoteDlg::getDB()
 {
     if (onlinePollerThread != NULL) {
-        onlinePollerThread->quit();
+        onlinePollerThread->stop();
+        onlinePollerThread->wait();
         delete onlinePollerThread;
         onlinePollerThread = NULL;
     }