diff --git a/services/native/file_access_service/src/file_access_service.cpp b/services/native/file_access_service/src/file_access_service.cpp index 200c8a87bdf18e137b45988555fc7be6e7f93805..da96b6a5b6e589ba6a776d3e1d3a81a38e9b6afa 100644 --- a/services/native/file_access_service/src/file_access_service.cpp +++ b/services/native/file_access_service/src/file_access_service.cpp @@ -209,16 +209,19 @@ void FileAccessService::ResetProxy(const wptr &remote) HILOG_DEBUG("FileAccessService::ResetProxy start"); lock_guard lock(mapMutex_); if (remote != nullptr && extensionDeathRecipient_ != nullptr) { - for (auto iter = cMap_.begin(); iter != cMap_.end(); ++iter) { + for (auto iter = cMap_.begin(); iter != cMap_.end();) { if (iter->second == nullptr) { HILOG_ERROR("iter->second is null or extensionDeathRecipient_ is null."); + ++iter; continue; } auto proxyRemote = iter->second->AsObject(); if (proxyRemote != nullptr && proxyRemote == remote.promote()) { proxyRemote->RemoveDeathRecipient(extensionDeathRecipient_); - cMap_.erase(iter->first); + iter = cMap_.erase(iter); + continue; } + ++iter; } } else { HILOG_ERROR("FileAccessService::ResetProxy, proxy is null or extensionDeathRecipient_ is null."); @@ -539,15 +542,15 @@ int32_t FileAccessService::UnregisterNotifyImpl(Uri uri, const sptrUnRef(); + // if data refcount is invalid, release this code. + if (!object->IsValid()) { + obsManager_.release(code); + } // node has other observers, do not need remove. if (obsNode->CheckObsCodeListNotEmpty()) { HILOG_DEBUG("Has code do not stopWatcher"); return ERR_OK; } - // if data refcount is invalid, release this code. - if (!object->IsValid()) { - obsManager_.release(code); - } return RmUriObsNodeRelations(uriStr, obsNode, info); }