From 6778e38ddc94160a5ada0cd9365f69ed9fc6a2df Mon Sep 17 00:00:00 2001 From: wangpggg Date: Fri, 23 Aug 2024 15:05:14 +0800 Subject: [PATCH] make judgment before using pointer Signed-off-by: wangpeng --- .../file_access_service/src/file_access_service.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 1b675930..93828f42 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)) { -- Gitee