From 3197dfd3f0459a3ab7b34d1eaab4e58979226f51 Mon Sep 17 00:00:00 2001 From: wangxu43 Date: Sat, 7 May 2022 16:38:22 +0800 Subject: [PATCH] Add nullptr check for new nothrow Signed-off-by: wangxu43 --- services/co_auth/src/auth_res_manager.cpp | 6 +++++- services/user_idm/src/useridm_controller.cpp | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/services/co_auth/src/auth_res_manager.cpp b/services/co_auth/src/auth_res_manager.cpp index d0e6d31..4fc60aa 100644 --- a/services/co_auth/src/auth_res_manager.cpp +++ b/services/co_auth/src/auth_res_manager.cpp @@ -68,7 +68,11 @@ uint64_t AuthResManager::Register(std::shared_ptr executorInfo, // Assign messenger sptr messenger = - new UserIAM::AuthResPool::ExecutorMessenger(&coAuthResPool_); + new (std::nothrow) UserIAM::AuthResPool::ExecutorMessenger(&coAuthResPool_); + if (messenger == nullptr) { + COAUTH_HILOGE(MODULE_SERVICE, "messenger is nullptr"); + return INVALID_EXECUTOR_ID; + } callback->OnMessengerReady(messenger); COAUTH_HILOGD(MODULE_SERVICE, "register is successfull, exeID is 0xXXXX%{public}04" PRIx64, MASK & executorId); return executorId; diff --git a/services/user_idm/src/useridm_controller.cpp b/services/user_idm/src/useridm_controller.cpp index ddf1843..27f9d5d 100644 --- a/services/user_idm/src/useridm_controller.cpp +++ b/services/user_idm/src/useridm_controller.cpp @@ -204,9 +204,13 @@ int32_t UserIDMController::UpdateCredentialCtrl(int32_t userId, uint64_t callerI data_->InsertScheduleId(scheduleId); std::shared_ptr coAuthCallback = std::make_shared(MODIFY_CRED, challenge, scheduleId, data_, innerkitsCallback); - sptr dr = new CoAuthCallbackDeathRecipient(coAuthCallback); - if (!innerkitsCallback->AsObject()->AddDeathRecipient(dr)) { - USERIDM_HILOGE(MODULE_SERVICE, "Failed to add death recipient CoAuthCallbackDeathRecipient"); + sptr dr = new (std::nothrow) CoAuthCallbackDeathRecipient(coAuthCallback); + if (dr == nullptr) { + COAUTH_HILOGE(MODULE_SERVICE, "dr is nullptr"); + } else { + if (!innerkitsCallback->AsObject()->AddDeathRecipient(dr)) { + USERIDM_HILOGE(MODULE_SERVICE, "Failed to add death recipient CoAuthCallbackDeathRecipient"); + } } CoAuth::AuthInfo paramInfo; paramInfo.SetPkgName(callerName); @@ -254,9 +258,13 @@ int32_t UserIDMController::DelFaceCredentialCtrl(AuthType authType, AuthSubType } std::shared_ptr setPropCallback = std::make_shared(FACE, 0, 0, credentialId, data_, innerCallback); - sptr dr = new SetPropCallbackDeathRecipient(setPropCallback); - if (!innerCallback->AsObject()->AddDeathRecipient(dr)) { - USERIDM_HILOGE(MODULE_SERVICE, "Failed to add death recipient SetPropCallbackDeathRecipient"); + sptr dr = new (std::nothrow) SetPropCallbackDeathRecipient(setPropCallback); + if (dr == nullptr) { + COAUTH_HILOGE(MODULE_SERVICE, "dr is nullptr"); + } else { + if (!innerCallback->AsObject()->AddDeathRecipient(dr)) { + USERIDM_HILOGE(MODULE_SERVICE, "Failed to add death recipient SetPropCallbackDeathRecipient"); + } } AuthResPool::AuthAttributes condition; condition.SetUint32Value(AuthAttributeType::AUTH_PROPERTY_MODE, 0);