diff --git a/frameworks/cj/ffi/src/notification_utils.cpp b/frameworks/cj/ffi/src/notification_utils.cpp index 6da22c8ab154ffce15c11a755aed07e2fa919d4a..d5d729b6c94946f66970883619e4a55a7d87bb24 100644 --- a/frameworks/cj/ffi/src/notification_utils.cpp +++ b/frameworks/cj/ffi/src/notification_utils.cpp @@ -1320,6 +1320,21 @@ namespace Notification { return true; } + static void freeNotificationButton(CNotificationButton &cButton) + { + if (cButton.names.head != nullptr) { + for (int64_t i = 0; i < cButton.names.size; i++) { + free(cButton.names.head[i]); + } + free(cButton.names.head); + cButton.names.head = nullptr; + } + if (cButton.icons.head != nullptr) { + free(cButton.icons.head); + cButton.icons.head = nullptr; + } + } + bool SetButtonV2(const NotificationLocalLiveViewButton &button, CNotificationButtonV2 &cButton) { // buttonNames: Array @@ -1347,6 +1362,7 @@ namespace Notification { icons.head = static_cast(malloc(sizeof(int64_t) * iconsVec.size())); if (icons.head == nullptr) { LOGE("NotificationButton icons malloc failed"); + freeNotificationButton(cButton); return false; } for (auto vec : iconsVec) { @@ -1357,6 +1373,8 @@ namespace Notification { auto native = FFIData::Create(vec); if (native == nullptr) { LOGE("Invalid object pixelMap of buttonIcons."); + cButton.icons = icons; + freeNotificationButton(cButton); return false; // memory free at cj } icons.head[iconCount++] = native->GetID(); diff --git a/frameworks/js/napi/src/manager/napi_get_active.cpp b/frameworks/js/napi/src/manager/napi_get_active.cpp index fb51ed0504ba7202bcf93c290c740d77cb6e7aa5..2e1ff088ead220643ac997a9fd1e702260cf8d42 100644 --- a/frameworks/js/napi/src/manager/napi_get_active.cpp +++ b/frameworks/js/napi/src/manager/napi_get_active.cpp @@ -434,7 +434,9 @@ napi_value NapiGetActiveNotificationByFilter(napi_env env, napi_callback_info in } napi_ref callback = nullptr; if (ParseGetLiveViewParams(env, info, asyncLiveViewCallBackInfo->filter, callback) == nullptr) { - ANS_LOGD("ParseGetLiveViewParams is nullptr."); + ANS_LOGE("ParseGetLiveViewParams is nullptr."); + delete asyncLiveViewCallBackInfo; + asyncLiveViewCallBackInfo = nullptr; Common::NapiThrow(env, ERROR_PARAM_INVALID); return Common::NapiGetUndefined(env); } diff --git a/frameworks/js/napi/src/subscribe/napi_subscribe.cpp b/frameworks/js/napi/src/subscribe/napi_subscribe.cpp index deb0ceec817d6cf022c945f3dc38383dc27256fd..81487d06360bb16697fac66c2ec6ff8d8fee73e4 100644 --- a/frameworks/js/napi/src/subscribe/napi_subscribe.cpp +++ b/frameworks/js/napi/src/subscribe/napi_subscribe.cpp @@ -40,6 +40,10 @@ void NapiDistributeOperationExecuteCallback(napi_env env, void *data) } sptr operationInfo = new (std::nothrow) NotificationOperationInfo(); + if (operationInfo == nullptr) { + ANS_LOGE("operationInfo is nullptr."); + return; + } operationInfo->SetHashCode(asyncCallbackInfo->hashCode); if (asyncCallbackInfo->operationInfo.withOperationInfo) { operationInfo->SetOperationType(OperationType::DISTRIBUTE_OPERATION_REPLY); diff --git a/services/ans/src/advanced_notification_live_view_service.cpp b/services/ans/src/advanced_notification_live_view_service.cpp index 55e622acbae760bbb4074aff060d9bf4f1e712db..c2e12b8f44bbaa078efd6070081fb4c100ddc65c 100644 --- a/services/ans/src/advanced_notification_live_view_service.cpp +++ b/services/ans/src/advanced_notification_live_view_service.cpp @@ -306,6 +306,8 @@ int32_t AdvancedNotificationService::GetNotificationRequestFromDb( auto *bundleOption = NotificationJsonConverter::ConvertFromJson(jsonObject); if (bundleOption == nullptr) { ANS_LOGE("Parse json string to bundle option failed, str: %{public}s.", value.c_str()); + delete request; + request = nullptr; return ERR_ANS_TASK_ERR; } @@ -368,6 +370,8 @@ int32_t AdvancedNotificationService::GetBatchNotificationRequestsFromDb( ANS_LOGE("Parse json string to bundle option failed."); (void)DoubleDeleteNotificationFromDb(request->GetKey(), request->GetSecureKey(), request->GetReceiverUserId()); + delete request; + request = nullptr; continue; }