From dfde8584ca4722a4906926ba5b6444b8bb521c98 Mon Sep 17 00:00:00 2001 From: Mateusz Malicki Date: Thu, 15 Jan 2015 16:20:12 +0100 Subject: [PATCH] Prevent from call method on partially destroyed object [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 | 8 ++++++-- server/zones-manager.cpp | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/zone.cpp b/server/zone.cpp index f6fb188..1c4d2b2 100644 --- a/server/zone.cpp +++ b/server/zone.cpp @@ -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& Zone::getPermittedToSend() const diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index 840d8c4..42a3a48 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -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"); } -- 2.7.4