Changed reapServices() to prevent possible crash 70/82570/1
authorkmook <kmook.choi@samsung.com>
Thu, 4 Aug 2016 08:02:00 +0000 (17:02 +0900)
committerkmook <kmook.choi@samsung.com>
Thu, 4 Aug 2016 08:02:00 +0000 (17:02 +0900)
Change-Id: I161c446bae427bb90967026ad0f6c00113e05d38
Signed-off-by: kmook <kmook.choi@samsung.com>
msf_tizen_client/src/SearchProvider.cpp

index 9323dc2..7de3810 100644 (file)
@@ -175,13 +175,18 @@ void SearchProvider::updateAlive(long ttl, string id, int service_type)
 void SearchProvider::reapServices()
 {
        map<string,ttl_info>::iterator it;
-       for(it=aliveMap.begin();it!=aliveMap.end();++it) {
+       it=aliveMap.begin();
+       while(it!=aliveMap.end()) {
                ttl_info info=it->second;
                if ( info.is_expired()) {
-                       Service service=getServiceByIp(it->first);
+                       map<string,ttl_info>::iterator toEraseIter = it;
+                       ++it;
+                       Service service=getServiceByIp(toEraseIter->first);
                        MSF_DBG("reapServices - Remove service : [%s]", service.getId().c_str());
-                       aliveMap.erase(it->first);
+                       aliveMap.erase(toEraseIter->first);
                        Search::removeServiceAndNotify(service);
+               } else {
+                       ++it;
                }
        }
 }