From df80d006044a3b1c86d55de286d524913233abfc Mon Sep 17 00:00:00 2001 From: z30053788 Date: Tue, 1 Apr 2025 21:37:08 +0800 Subject: [PATCH 1/2] update Signed-off-by: z30053788 Change-Id: Ifbab83f5e228748b84d4a06be2aaee0952948286 --- frameworks/cj/ffi/src/notification_utils.cpp | 18 ++++++++++++++++++ .../js/napi/src/subscribe/napi_subscribe.cpp | 4 ++++ ...advanced_notification_live_view_service.cpp | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/frameworks/cj/ffi/src/notification_utils.cpp b/frameworks/cj/ffi/src/notification_utils.cpp index 6da22c8ab..d5d729b6c 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/subscribe/napi_subscribe.cpp b/frameworks/js/napi/src/subscribe/napi_subscribe.cpp index deb0ceec8..81487d063 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 55e622acb..c2e12b8f4 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; } -- Gitee From 5db83ba17c3fe817f96133fa5f8eb5f4ddb63c11 Mon Sep 17 00:00:00 2001 From: z30053788 Date: Tue, 29 Apr 2025 15:20:39 +0800 Subject: [PATCH 2/2] update Signed-off-by: z30053788 Change-Id: I8eb5f683db88e1e4e394843b0437a66c7e2f0b9c --- frameworks/js/napi/src/manager/napi_get_active.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frameworks/js/napi/src/manager/napi_get_active.cpp b/frameworks/js/napi/src/manager/napi_get_active.cpp index fb51ed050..2e1ff088e 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); } -- Gitee