From: Lukasz Bardeli Date: Wed, 3 Jan 2018 12:09:24 +0000 (+0100) Subject: [Download] fix crash while getting map element X-Git-Tag: submit/tizen/20180115.103658^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a728282804ead74c16df240175aac789d0e5399;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Download] fix crash while getting map element There may be situation when while destroying DownloadInfoPtr in DownloadInstance destructor on second thread static method is called and check if instance is exist and later try to read info from DownloadInfoPtr. To avoid this situation lock_guard is moved just before part of code responsible for destroying DownloadInfoPtr [Verification] Code compiles without error. 100% passrate Change-Id: I20b0b0fc1b021d91d2f7daaf36500e4c2b83766c --- diff --git a/src/download/download_instance.cc b/src/download/download_instance.cc index e34d1aa5..52923da8 100644 --- a/src/download/download_instance.cc +++ b/src/download/download_instance.cc @@ -61,6 +61,9 @@ DownloadInstance::DownloadInstance() { DownloadInstance::~DownloadInstance() { ScopeLogger(); int ret; + + std::lock_guard lock(instances_mutex_); + for (DownloadCallbackMap::iterator it = download_callbacks.begin(); it != download_callbacks.end(); ++it) { DownloadInfoPtr diPtr = it->second->instance->diMap[it->second->callbackId]; @@ -89,7 +92,6 @@ DownloadInstance::~DownloadInstance() { delete (it->second); } - std::lock_guard lock(instances_mutex_); for (auto it = instances_.begin(); it != instances_.end(); it++) { if (*it == this) { instances_.erase(it);