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
DownloadInstance::~DownloadInstance() {
ScopeLogger();
int ret;
+
+ std::lock_guard<std::mutex> lock(instances_mutex_);
+
for (DownloadCallbackMap::iterator it = download_callbacks.begin();
it != download_callbacks.end(); ++it) {
DownloadInfoPtr diPtr = it->second->instance->diMap[it->second->callbackId];
delete (it->second);
}
- std::lock_guard<std::mutex> lock(instances_mutex_);
for (auto it = instances_.begin(); it != instances_.end(); it++) {
if (*it == this) {
instances_.erase(it);