diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 8e276a232153ce1efdc016a5a98fb434b4307164..c381afc67978d00882f760eac86316e12c53968a 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -107,7 +107,7 @@ void DeviceManagerNotify::RegisterDeviceStatusCallback(const std::string &pkgNam } std::lock_guard autoLock(lock_); if (deviceStatusCallback_.size() >= MAX_CONTAINER_SIZE) { - LOGE("deviceStateCallback_ map size is more than max size"); + LOGE("deviceStatusCallback_ map size is more than max size"); return; } deviceStatusCallback_[pkgName] = callback; @@ -191,7 +191,7 @@ void DeviceManagerNotify::RegisterAuthenticateCallback(const std::string &pkgNam std::lock_guard autoLock(lock_); if (authenticateCallback_.count(pkgName) == 0) { if (authenticateCallback_.size() >= MAX_CONTAINER_SIZE) { - LOGE("devicePublishCallbacks_ map size is more than max size"); + LOGE("authenticateCallback_ map size is more than max size"); return; } authenticateCallback_[pkgName] = std::map>(); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index bfdd9d6694ea51ee5e1eb3aee95e150f79ecc76e..df954de305fa96460671dbea90c5997253008d97 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -3291,6 +3291,8 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) std::lock_guard autoLock(g_deviceManagerMapMutex); if (g_deviceManagerMap.size() >= MAX_CONTAINER_SIZE) { LOGE("g_deviceManagerMap map size is more than max size"); + delete obj; + obj = nullptr; return nullptr; } g_deviceManagerMap[obj->bundleName_] = obj; diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 7b2458277d316016eec2993b85710996678e3702..a7894642a3c4e584bb7caa9ebf37b488a53dc213 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -2853,6 +2853,8 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) std::lock_guard autoLock(g_deviceManagerMapMutex); if (g_deviceManagerMap.size() >= MAX_CONTAINER_SIZE) { LOGE("g_deviceManagerMap map size is more than max size"); + delete obj; + obj = nullptr; return nullptr; } g_deviceManagerMap[obj->bundleName_] = obj; diff --git a/utils/BUILD.gn b/utils/BUILD.gn index b533b2e49bcbcb25f65a09f9c7df111d74186e46..c4d1ba8fe5106a23dc36a67e65a175e117e5a6a1 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -46,7 +46,6 @@ if (defined(ohos_lite)) { "${common_path}/src/dfx/lite/dm_hisysevent.cpp", "${common_path}/src/dfx/lite/dm_hitrace.cpp", "${common_path}/src/dm_anonymous.cpp", - "${common_path}/src/dm_constants.cpp", "${common_path}/src/dm_error_message.cpp", "${common_path}/src/ipc/lite/ipc_cmd_register.cpp", "src/appInfo/lite/app_manager.cpp", @@ -129,7 +128,6 @@ if (defined(ohos_lite)) { sources = [ "${common_path}/src/dm_anonymous.cpp", - "${common_path}/src/dm_constants.cpp", "src/appInfo/standard/app_manager.cpp", "src/crypto/dm_crypto.cpp", "src/dm_random.cpp", @@ -210,7 +208,6 @@ if (defined(ohos_lite)) { sources = [ "${common_path}/src/dm_anonymous.cpp", - "${common_path}/src/dm_constants.cpp", "src/appInfo/standard/app_manager.cpp", "src/crypto/dm_crypto.cpp", "src/dm_random.cpp", diff --git a/utils/src/appInfo/standard/app_manager.cpp b/utils/src/appInfo/standard/app_manager.cpp index 42cf4b60a12ad73a6ab50e9f9bab17476bb6f2d3..b9537ca5ffa654d2a6b40676fd7250c1a58c8b53 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -24,7 +24,6 @@ #include "system_ability_definition.h" #include "tokenid_kit.h" -#include "dm_constants.h" #include "dm_anonymous.h" #include "dm_error_type.h" #include "dm_log.h" @@ -33,6 +32,9 @@ using namespace OHOS::Security::AccessToken; namespace OHOS { namespace DistributedHardware { +namespace { +const int32_t MAX_CONTAINER_SIZE = 1000; +} DM_IMPLEMENT_SINGLE_INSTANCE(AppManager); const std::string AppManager::GetAppId()