Add nullptr check for new nothrow

Signed-off-by: wangxu43 <wangxu43@huawei.com>
This commit is contained in:
wangxu43 2022-05-07 16:38:22 +08:00
parent 39a02f5caf
commit 34060e0361
2 changed files with 19 additions and 7 deletions

View File

@ -68,7 +68,11 @@ uint64_t AuthResManager::Register(std::shared_ptr<ResAuthExecutor> executorInfo,
// Assign messenger
sptr<UserIAM::AuthResPool::IExecutorMessenger> 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;

View File

@ -204,9 +204,13 @@ int32_t UserIDMController::UpdateCredentialCtrl(int32_t userId, uint64_t callerI
data_->InsertScheduleId(scheduleId);
std::shared_ptr<UserIDMCoAuthHandler> coAuthCallback =
std::make_shared<UserIDMCoAuthHandler>(MODIFY_CRED, challenge, scheduleId, data_, innerkitsCallback);
sptr<IRemoteObject::DeathRecipient> dr = new CoAuthCallbackDeathRecipient(coAuthCallback);
if (!innerkitsCallback->AsObject()->AddDeathRecipient(dr)) {
USERIDM_HILOGE(MODULE_SERVICE, "Failed to add death recipient CoAuthCallbackDeathRecipient");
sptr<IRemoteObject::DeathRecipient> 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<UserIDMSetPropHandler> setPropCallback =
std::make_shared<UserIDMSetPropHandler>(FACE, 0, 0, credentialId, data_, innerCallback);
sptr<IRemoteObject::DeathRecipient> dr = new SetPropCallbackDeathRecipient(setPropCallback);
if (!innerCallback->AsObject()->AddDeathRecipient(dr)) {
USERIDM_HILOGE(MODULE_SERVICE, "Failed to add death recipient SetPropCallbackDeathRecipient");
sptr<IRemoteObject::DeathRecipient> 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);