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 1b675930b82325faff93ab80e8a344d18a1f8d2f..93828f424f326e871b2d3d783c52d34793159b2c 100644 --- a/services/native/file_access_service/src/file_access_service.cpp +++ b/services/native/file_access_service/src/file_access_service.cpp @@ -307,17 +307,18 @@ int32_t FileAccessService::OperateObsNode(Uri &uri, bool notifyForDescendants, u { string uriStr = uri.ToString(); HILOG_INFO("OperateObsNode uriStr: %{public}s", uriStr.c_str()); - shared_ptr obsNode; { lock_guard lock(nodeMutex_); auto iter = relationshipMap_.find(uriStr); if (iter != relationshipMap_.end()) { - obsNode = iter->second; + auto obsNode = iter->second; // this node has this callback or not, if has this, unref manager. auto haveCodeIter = find_if(obsNode->obsCodeList_.begin(), obsNode->obsCodeList_.end(), [code](const uint32_t &listCode) { return code == listCode; }); if (haveCodeIter != obsNode->obsCodeList_.end()) { - obsManager_.get(code)->UnRef(); + if (obsManager_.get(code) != nullptr) { + obsManager_.get(code)->UnRef(); + } if (obsNode->needChildNote_ == notifyForDescendants) { HILOG_DEBUG("Register same uri and same callback and same notifyForDescendants"); return ERR_OK; @@ -340,7 +341,7 @@ int32_t FileAccessService::OperateObsNode(Uri &uri, bool notifyForDescendants, u extensionProxy->StartWatcher(uri); { lock_guard lock(nodeMutex_); - obsNode = make_shared(notifyForDescendants); + auto obsNode = make_shared(notifyForDescendants); // add new node relations. for (auto &[comUri, node] : relationshipMap_) { if (IsParentUri(comUri, uriStr)) {