From dc60ed196bb54b289cbe47e3609fae10b33555ac Mon Sep 17 00:00:00 2001 From: bjd Date: Sat, 7 Jun 2025 16:29:52 +0800 Subject: [PATCH] bugfix Signed-off-by: bjd --- .../app/src/kvstore_data_service.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 2a7af16e4..82fc5095d 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -90,6 +90,7 @@ constexpr int MAX_DOWNLOAD_ASSETS_COUNT = 50; constexpr int MAX_DOWNLOAD_TASK = 5; constexpr int KEY_SIZE = 32; constexpr int AES_256_NONCE_SIZE = 32; +constexpr int MAX_CLIENT_DEATH_OBSERVER_SIZE = 16; KvStoreDataService::KvStoreDataService(bool runOnCreate) : SystemAbility(runOnCreate), clients_() @@ -851,8 +852,12 @@ void KvStoreDataService::KvStoreClientDeathObserverImpl::Reset() bool KvStoreDataService::KvStoreClientDeathObserverImpl::Insert(sptr observer, const std::string &featureName) { - observer->AddDeathRecipient(deathRecipient_); - return observerProxy_.insert_or_assign(featureName, std::move(observer)).second; + if (observerProxy_.size() < MAX_CLIENT_DEATH_OBSERVER_SIZE && + observerProxy_.insert_or_assign(featureName, observer).second) { + observer->AddDeathRecipient(deathRecipient_); + return true; + } + return false; } bool KvStoreDataService::KvStoreClientDeathObserverImpl::Delete(const std::string &featureName) -- Gitee