From 3005d4148475a651cec544f66381ba15461ee503 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Wed, 3 May 2023 22:28:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9NAPIDeathRecipient=E5=B0=86na?= =?UTF-8?q?pi=5Fdelete=5Freference=E6=94=BE=E5=9C=A8OnRemoteDied=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wanderer-dl122 --- .../napi_common/include/napi_remote_proxy_holder.h | 2 +- .../source/napi_remote_proxy_holder.cpp | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/ipc/native/src/napi_common/include/napi_remote_proxy_holder.h b/ipc/native/src/napi_common/include/napi_remote_proxy_holder.h index 42c5a72..868b05f 100644 --- a/ipc/native/src/napi_common/include/napi_remote_proxy_holder.h +++ b/ipc/native/src/napi_common/include/napi_remote_proxy_holder.h @@ -34,7 +34,7 @@ public: bool Matches(napi_value object); protected: - virtual ~NAPIDeathRecipient(); + virtual ~NAPIDeathRecipient() = default; private: struct OnRemoteDiedParam { diff --git a/ipc/native/src/napi_common/source/napi_remote_proxy_holder.cpp b/ipc/native/src/napi_common/source/napi_remote_proxy_holder.cpp index d0c0bf5..fc1d53f 100644 --- a/ipc/native/src/napi_common/source/napi_remote_proxy_holder.cpp +++ b/ipc/native/src/napi_common/source/napi_remote_proxy_holder.cpp @@ -33,17 +33,6 @@ NAPIDeathRecipient::NAPIDeathRecipient(napi_env env, napi_value jsDeathRecipient NAPI_ASSERT_RETURN_VOID(env, status == napi_ok, "failed to create ref to js death recipient"); } -NAPIDeathRecipient::~NAPIDeathRecipient() -{ - if (env_ != nullptr) { - if (deathRecipientRef_ != nullptr) { - napi_status status = napi_delete_reference(env_, deathRecipientRef_); - NAPI_ASSERT_RETURN_VOID(env_, status == napi_ok, "failed to delete ref to js death recipient"); - deathRecipientRef_ = nullptr; - } - } -} - void NAPIDeathRecipient::OnRemoteDied(const wptr &object) { if (deathRecipientRef_ == nullptr) { @@ -78,6 +67,9 @@ void NAPIDeathRecipient::OnRemoteDied(const wptr &object) if (returnVal == nullptr) { ZLOGE(LOG_LABEL, "failed to call function onRemoteDied"); } + + napi_status napiStatus = napi_delete_reference(param->env, param->deathRecipientRef); + NAPI_ASSERT_RETURN_VOID(param->env, napiStatus == napi_ok, "failed to delete ref to js death recipient"); delete param; delete work; }); -- GitLab