From c0649fbbb2f914b3dae953b812f3a016d2ec04b2 Mon Sep 17 00:00:00 2001 From: wuyongning Date: Tue, 22 Mar 2022 09:22:42 +0800 Subject: [PATCH 1/3] Signed-off-by: wuyongning Changes to be committed: --- services/distributeddataservice/app/src/backup_handler.cpp | 5 ++++- .../framework/include/serializable/serializable.h | 5 ++++- .../service/config/src/config_factory.cpp | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/app/src/backup_handler.cpp b/services/distributeddataservice/app/src/backup_handler.cpp index ac0eae47c..20ccc6b8f 100644 --- a/services/distributeddataservice/app/src/backup_handler.cpp +++ b/services/distributeddataservice/app/src/backup_handler.cpp @@ -97,8 +97,11 @@ void BackupHandler::SingleKvStoreBackup(const MetaData &metaData) dbOption.createDirByStoreIdOnly = true; dbOption.secOption = KvStoreAppManager::ConvertSecurity(metaData.kvStoreMetaData.securityLevel); - auto *delegateMgr = new DistributedDB::KvStoreDelegateManager(metaData.kvStoreMetaData.appId, + auto *delegateMgr = new(std::nothrow) DistributedDB::KvStoreDelegateManager(metaData.kvStoreMetaData.appId, AccountDelegate::GetInstance()->GetCurrentAccountId(metaData.kvStoreMetaData.bundleName)); + if (delegateMgr == nullptr) { + return delegateMgr; + } std::string appDataStoragePath = KvStoreAppManager::GetDataStoragePath(metaData.kvStoreMetaData.deviceAccountId, metaData.kvStoreMetaData.bundleName, backupPara.pathType); diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 6387e19aa..047a1abf6 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -74,7 +74,10 @@ protected: if (subNode.is_null()) { return false; } - value = new T(); + value = new(std::nothrow) T(); + if (value == nullptr) { + return value; + } bool result = GetValue(subNode, "", *value); if (!result) { delete value; diff --git a/services/distributeddataservice/service/config/src/config_factory.cpp b/services/distributeddataservice/service/config/src/config_factory.cpp index 796b2cecb..986ea20b3 100644 --- a/services/distributeddataservice/service/config/src/config_factory.cpp +++ b/services/distributeddataservice/service/config/src/config_factory.cpp @@ -43,6 +43,7 @@ int32_t ConfigFactory::Initialize() std::getline(fin, line); jsonStr += line; } + fin.close(); config_.Unmarshall(jsonStr); isInited = true; return 0; -- Gitee From 2964bffc2a8d86daaba3f68de8476f928edeec6e Mon Sep 17 00:00:00 2001 From: wuyongning Date: Tue, 22 Mar 2022 09:51:40 +0800 Subject: [PATCH 2/3] Signed-off-by: wuyongning Changes to be committed: --- services/distributeddataservice/app/src/backup_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/backup_handler.cpp b/services/distributeddataservice/app/src/backup_handler.cpp index 20ccc6b8f..1ef5a8596 100644 --- a/services/distributeddataservice/app/src/backup_handler.cpp +++ b/services/distributeddataservice/app/src/backup_handler.cpp @@ -100,7 +100,7 @@ void BackupHandler::SingleKvStoreBackup(const MetaData &metaData) auto *delegateMgr = new(std::nothrow) DistributedDB::KvStoreDelegateManager(metaData.kvStoreMetaData.appId, AccountDelegate::GetInstance()->GetCurrentAccountId(metaData.kvStoreMetaData.bundleName)); if (delegateMgr == nullptr) { - return delegateMgr; + return; } std::string appDataStoragePath = KvStoreAppManager::GetDataStoragePath(metaData.kvStoreMetaData.deviceAccountId, -- Gitee From d936f69e6bccb3c00e6f484163c8de98f4822caa Mon Sep 17 00:00:00 2001 From: wuyongning Date: Tue, 22 Mar 2022 18:32:50 +0800 Subject: [PATCH 3/3] Signed-off-by: wuyongning Changes to be committed: --- services/distributeddataservice/app/src/query_helper.cpp | 2 +- .../framework/include/serializable/serializable.h | 2 +- .../service/config/src/config_factory.cpp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/app/src/query_helper.cpp b/services/distributeddataservice/app/src/query_helper.cpp index cb56bf8a5..c11c417e9 100644 --- a/services/distributeddataservice/app/src/query_helper.cpp +++ b/services/distributeddataservice/app/src/query_helper.cpp @@ -36,7 +36,7 @@ DistributedDB::Query QueryHelper::StringToDbQuery(const std::string &query, bool { ZLOGI("query string length:%{public}zu", query.length()); DistributedDB::Query dbQuery = DistributedDB::Query::Select(); - if (query.size() == 0) { + if (query.empty()) { ZLOGI("Query string is empty."); isSuccess = true; return dbQuery; diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 047a1abf6..71fe7adfe 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -76,7 +76,7 @@ protected: } value = new(std::nothrow) T(); if (value == nullptr) { - return value; + return false; } bool result = GetValue(subNode, "", *value); if (!result) { diff --git a/services/distributeddataservice/service/config/src/config_factory.cpp b/services/distributeddataservice/service/config/src/config_factory.cpp index 986ea20b3..796b2cecb 100644 --- a/services/distributeddataservice/service/config/src/config_factory.cpp +++ b/services/distributeddataservice/service/config/src/config_factory.cpp @@ -43,7 +43,6 @@ int32_t ConfigFactory::Initialize() std::getline(fin, line); jsonStr += line; } - fin.close(); config_.Unmarshall(jsonStr); isInited = true; return 0; -- Gitee