Prevent from call method on partially destroyed object 56/33856/2
authorMateusz Malicki <m.malicki2@samsung.com>
Thu, 15 Jan 2015 15:20:12 +0000 (16:20 +0100)
committerJan Olszak <j.olszak@samsung.com>
Thu, 15 Jan 2015 16:52:39 +0000 (08:52 -0800)
[Bug]           startAsync can cause call method on partially destroyed object
[Cause]         async call are processed while ZoneManager is being destroyed
[Solution]      Ensure that all async calls was ended
[Verification]  Set EVENT_TIMEOUT=5 (ut-zones-manager.cpp), build, install,
                run ZonesManagerSuite/StartShutdownZoneTest with 1000
                times less speed.

Change-Id: I00bc8c0926be8a9a62ec23b81f62a2827db4799b

server/zone.cpp
server/zones-manager.cpp

index f6fb188..1c4d2b2 100644 (file)
@@ -81,8 +81,12 @@ Zone::~Zone()
     // Make sure all OnNameLostCallbacks get finished and no new will
     // get called before proceeding further. This guarantees no race
     // condition on the reconnect thread.
-    Lock lock(mReconnectMutex);
-    disconnect();
+    {
+        Lock lock(mReconnectMutex);
+        disconnect();
+    }
+    // wait for all tasks to complete
+    mWorker.reset();
 }
 
 const std::vector<boost::regex>& Zone::getPermittedToSend() const
index 840d8c4..42a3a48 100644 (file)
@@ -187,6 +187,8 @@ ZonesManager::~ZonesManager()
             LOGE("Failed to stop all of the zones");
         }
     }
+    // wait for all tasks to complete
+    mWorker.reset();
 
     LOGD("ZonesManager object destroyed");
 }