diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp index 9e36b5b5fd2a859758573ff2d543e6df025c2389..72535dbd5e2d2df3ee5796be099238e3856be1fc 100644 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp @@ -142,7 +142,10 @@ int32_t BundleDaemon::RegisterCallbackInvoke(IpcIo *req) if (!(ReadRemoteObject(req, &svcIdentity))) { return EC_INVALID; } - BundleDaemon::GetInstance().bundleMsClient_ = new BundleMsClient(svcIdentity); + BundleDaemon::GetInstance().bundleMsClient_ = new (std::nothrow) BundleMsClient(svcIdentity); + if (BundleDaemon::GetInstance().bundleMsClient_ == nullptr) { + return EC_BADPTR; + } return BundleDaemon::GetInstance().bundleMsClient_->SendReply(EC_SUCCESS); } diff --git a/services/bundlemgr_lite/src/bundle_manager_service.cpp b/services/bundlemgr_lite/src/bundle_manager_service.cpp index f72805e76856ac01d20ff12c3b9c3f9de4cbe596..12c817ceffd6f3537be34fc75c4dac200ea6aaa1 100644 --- a/services/bundlemgr_lite/src/bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/bundle_manager_service.cpp @@ -49,7 +49,7 @@ extern "C" { namespace OHOS { ManagerService::ManagerService() { - installer_ = new BundleInstaller(INSTALL_PATH, DATA_PATH); + installer_ = new (std::nothrow) BundleInstaller(INSTALL_PATH, DATA_PATH); bundleMap_ = BundleMap::GetInstance(); } @@ -182,7 +182,7 @@ void ManagerService::ServiceMsgProcess(Request* request) } if (installer_ == nullptr) { - installer_ = new BundleInstaller(INSTALL_PATH, DATA_PATH); + installer_ = new (std::nothrow) BundleInstaller(INSTALL_PATH, DATA_PATH); } switch (request->msgId) { diff --git a/services/bundlemgr_lite/src/bundle_map.cpp b/services/bundlemgr_lite/src/bundle_map.cpp index e20bfe6586eb6316f8f2cdef2651ed5229e499ad..2303f6c13a7077b888cc14e0eb4804c877456b5a 100755 --- a/services/bundlemgr_lite/src/bundle_map.cpp +++ b/services/bundlemgr_lite/src/bundle_map.cpp @@ -41,7 +41,7 @@ BundleMap::BundleMap() #else g_bundleListMutex = osMutexNew(reinterpret_cast(NULL)); #endif - bundleInfos_ = new List(); + bundleInfos_ = new (std::nothrow) List(); } BundleMap::~BundleMap() @@ -83,7 +83,7 @@ bool BundleMap::Update(BundleInfo *bundleInfo) #else MutexAcquire(&g_bundleListMutex, BUNDLELIST_MUTEX_TIMEOUT); #endif - auto newNode = new Node(bundleInfo); + auto newNode = new (std::nothrow) Node(bundleInfo); if (newNode == nullptr) { MutexRelease(&g_bundleListMutex); return false; diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 01aa5446b865e7b677f091dd2de07719d7625b2d..510ef582c40a78cb3e4dc3ac54f431150eadf6e5 100644 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -47,8 +47,8 @@ const uint8_t BMS_INSTALLATION_COMPLETED = 100; GtManagerService::GtManagerService() { - installer_ = new GtBundleInstaller(); - bundleResList_ = new List(); + installer_ = new (std::nothrow) GtBundleInstaller(); + bundleResList_ = new (std::nothrow) List(); bundleMap_ = BundleMap::GetInstance(); bundleInstallMsg_ = nullptr; jsEngineVer_ = nullptr; @@ -56,7 +56,7 @@ GtManagerService::GtManagerService() preAppList_ = nullptr; updateFlag_ = false; oldVersionCode_ = -1; - listenList_ = new List(); + listenList_ = new (std::nothrow) List(); } GtManagerService::~GtManagerService() @@ -73,7 +73,7 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP InstallerCallback installerCallback) { if (installer_ == nullptr) { - installer_ = new GtBundleInstaller(); + installer_ = new (std::nothrow) GtBundleInstaller(); } if (hapPath == nullptr) { return false; @@ -170,7 +170,7 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins InstallerCallback installerCallback) { if (installer_ == nullptr) { - installer_ = new GtBundleInstaller(); + installer_ = new (std::nothrow) GtBundleInstaller(); } if (bundleName == nullptr) { HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Parsed bundleName to be uninstalled is null"); @@ -298,7 +298,7 @@ uint8_t GtManagerService::QueryAbilityInfos(const Want *want, AbilityInfo **abil return 0; } int32_t abilityInfoLen = 0; - List *bundleInfos_ = new List(); + List *bundleInfos_ = new (std::nothrow) List(); bundleMap_->GetBundleInfosInner(*bundleInfos_); for (auto node = bundleInfos_->Begin(); node != bundleInfos_->End(); node = node->next_) { diff --git a/services/bundlemgr_lite/src/zip_file.cpp b/services/bundlemgr_lite/src/zip_file.cpp index c680ba535b190467e2f1fd9d479d0ed8b64afce0..c6b3184741e21e2b49eac9a3a1a496fd167842a4 100755 --- a/services/bundlemgr_lite/src/zip_file.cpp +++ b/services/bundlemgr_lite/src/zip_file.cpp @@ -437,13 +437,13 @@ bool ZipFile::InitZStream(z_stream &zstream) const return false; } - BytePtr bufOut = new Byte[UNZIP_BUF_OUT_LEN]; + BytePtr bufOut = new (std::nothrow) Byte[UNZIP_BUF_OUT_LEN]; if (bufOut == nullptr) { HILOG_ERROR(HILOG_MODULE_APP, "unzip inflated new out buffer failed"); return false; } - BytePtr bufIn = new Byte[UNZIP_BUF_IN_LEN]; + BytePtr bufIn = new (std::nothrow) Byte[UNZIP_BUF_IN_LEN]; if (bufIn == nullptr) { HILOG_ERROR(HILOG_MODULE_APP, "unzip inflated new in buffer failed"); delete[] bufOut; diff --git a/utils/bundle_lite/utils_list.h b/utils/bundle_lite/utils_list.h index 60c64e8406616bc74ee883e11fa687ebd18259de..2f47291add7677f3b8625d3d0092f9a427a7a25b 100644 --- a/utils/bundle_lite/utils_list.h +++ b/utils/bundle_lite/utils_list.h @@ -32,7 +32,7 @@ class List { public: List() : count_(0) { - head_ = new Node(); + head_ = new (std::nothrow) Node(); head_->next_ = head_; head_->prev_ = head_; } @@ -55,7 +55,7 @@ public: void PushFront(T value) { - auto node = new Node(value); + auto node = new (std::nothrow) Node(value); if (node == nullptr) { return; } @@ -91,7 +91,7 @@ public: void PushBack(T value) { - auto node = new Node(value); + auto node = new (std::nothrow) Node(value); node->next_ = head_; node->prev_ = head_->prev_;