diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp index 4e5e29b04eac7e6b3eb3cdfa75bab08b493bbffa..360724f8350a8a13488271315f1601d42c4ca463 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp @@ -197,7 +197,7 @@ void BundleMgrProxy::Delete(const std::string &bundleName, int32_t userId, int32 std::shared_ptr BundleMgrProxy::GetInstance() { - static std::shared_ptr proxy(new BundleMgrProxy()); + static std::shared_ptr proxy = std::make_shared(); return proxy; } diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.h b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.h index c0c3d774e82fdbdbe7415ee47e27ef63020e1910..bc432d62cd5c7c6c4aaa067e5a60f71758a6b3ed 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.h +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.h @@ -57,24 +57,24 @@ struct ExtensionAbilityInfo { struct BundleConfig { std::string name; bool singleton = false; - bool isSystemApp = false; + bool isSystemApp = false; std::vector hapModuleInfos; std::vector extensionInfos; }; class BundleMgrProxy final : public std::enable_shared_from_this { public: + BundleMgrProxy() = default; ~BundleMgrProxy(); static std::shared_ptr GetInstance(); int GetBundleInfoFromBMS(const std::string &bundleName, int32_t userId, BundleConfig &bundleConfig, int32_t appIndex = 0); - int GetBundleInfoFromBMSWithCheck(const std::string &bundleName, int32_t userId, - BundleConfig &bundleConfig, int32_t appIndex = 0); + int GetBundleInfoFromBMSWithCheck(const std::string &bundleName, int32_t userId, + BundleConfig &bundleConfig, int32_t appIndex = 0); void Delete(const std::string &bundleName, int32_t userId, int32_t appIndex); sptr CheckBMS(); std::pair GetCallerAppIdentifier(const std::string &bundleName, int32_t userId); private: - BundleMgrProxy() = default; class ServiceDeathRecipient : public IRemoteObject::DeathRecipient { public: explicit ServiceDeathRecipient(std::weak_ptr owner) : owner_(owner) {} diff --git a/services/distributeddataservice/service/data_share/common/common_utils.h b/services/distributeddataservice/service/data_share/common/common_utils.h index 1b8379dc7fdb2f7329ceaac9acabeda848921454..a526fbf62334ee1d96990fddd7c1282711aef220 100644 --- a/services/distributeddataservice/service/data_share/common/common_utils.h +++ b/services/distributeddataservice/service/data_share/common/common_utils.h @@ -30,5 +30,11 @@ bool CheckSystemAbility(uint32_t tokenId); bool CheckSystemCallingPermission(uint32_t tokenId, uint64_t fullTokenId); +inline int64_t GetSystemTime() +{ + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); +} + } // namespace OHOS::DataShare #endif // DATASHARESERVICE_COMMON_UTILS_H diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index de1036ff2b24476a28b4730fe59b0adbbbd37c79..f096e975b73f79fcf6289747501a977a50ef0eb4 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -35,6 +35,7 @@ #include "db_delegate.h" #include "log_debug.h" #include "ipc_skeleton.h" +#include "common_utils.h" namespace OHOS::DataShare { constexpr static int32_t MAX_RESULTSET_COUNT = 32; @@ -216,7 +217,6 @@ std::pair> RdbDelegate::Query(const std return std::make_pair(errCode_, nullptr); } int count = resultSetCount.fetch_add(1); - ZLOGD_MACRO("start query %{public}d", count); if (count >= MAX_RESULTSET_COUNT && IsLimit(count, callingPid, callingTokenId)) { resultSetCount--; return std::make_pair(E_RESULTSET_BUSY, nullptr); @@ -240,14 +240,15 @@ std::pair> RdbDelegate::Query(const std ++value; return true; }); - int64_t beginTime = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); + int64_t beginTime = GetSystemTime(); auto bridge = RdbDataShareAdapter::RdbUtils::ToResultSetBridge(resultSet); - std::shared_ptr result = { new DataShareResultSet(bridge), [callingPid, beginTime](auto p) { - ZLOGD_MACRO("release resultset"); + auto resultSetPtr = new (std::nothrow) DataShareResultSet(bridge); + if (resultSetPtr == nullptr) { + return std::make_pair(E_ERROR, nullptr); + } + auto result = std::shared_ptr(resultSetPtr, [callingPid, beginTime](auto p) { resultSetCount--; - int64_t endTime = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); + int64_t endTime = GetSystemTime(); if (endTime - beginTime > TIMEOUT_TIME) { ZLOGE("pid %{public}d query time is %{public}" PRId64 ", %{public}d resultSet is used.", callingPid, (endTime - beginTime), resultSetCount.load()); @@ -257,7 +258,7 @@ std::pair> RdbDelegate::Query(const std return value > 0; }); delete p; - }}; + }); return std::make_pair(E_OK, result); } diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 99bff919b6aa61984658fe159dd480456ff75b2a..b914b79547dbe8c073804435c614ea724a0bafe0 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -613,7 +613,11 @@ void DataShareServiceImpl::SubscribeCommonEvent() ZLOGE("System mgr is nullptr"); return; } - sptr callback(new SystemAbilityStatusChangeListener()); + sptr callback(new (std::nothrow)SystemAbilityStatusChangeListener()); + if (callback == nullptr) { + ZLOGE("new SystemAbilityStatusChangeListener failed! no memory"); + return; + } systemManager->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, callback); } @@ -624,7 +628,11 @@ void DataShareServiceImpl::SubscribeConcurrentTask() ZLOGE("System mgr is nullptr"); return; } - sptr callback(new SystemAbilityStatusChangeListener()); + sptr callback(new (std::nothrow)SystemAbilityStatusChangeListener()); + if (callback == nullptr) { + ZLOGE("new SystemAbilityStatusChangeListener failed! no memory"); + return; + } systemManager->SubscribeSystemAbility(CONCURRENT_TASK_SERVICE_ID, callback); }