From 29e132eb6e885565fe843cfb08d44bb8b43a3973 Mon Sep 17 00:00:00 2001 From: z30054037 Date: Fri, 27 Oct 2023 07:30:36 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=91=8A=E8=AD=A6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0scope=E4=BD=9C=E7=94=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5efd5907e294c6efda6c924621961e809e5ea0c5 Signed-off-by: z30054037 --- .../native/backup_ext/src/ext_backup_js.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index ad919e7a9..edccf655b 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -300,30 +300,41 @@ static int DoCallJsMethod(CallJsParam *param) } AbilityRuntime::HandleEscape handleEscape(*jsRuntime); auto env = jsRuntime->GetNapiEnv(); - vector argv; + napi_handle_scope scope = nullptr; + napi_open_handle_scope(env, &scope); + if (scope == nullptr) { + HILOGE("scope is nullptr"); + return EINVAL; + } + vector argv = {}; if (param->argParser != nullptr) { if (!param->argParser(env, argv)) { HILOGE("failed to get params."); + napi_close_handle_scope(env, scope); return EINVAL; } } napi_value value = param->jsObj->GetNapiValue(); if (value == nullptr) { HILOGE("failed to get napi value object."); + napi_close_handle_scope(env, scope); return EINVAL; } napi_value method; napi_get_named_property(env, value, param->funcName.c_str(), &method); if (param->retParser == nullptr) { HILOGE("ResultValueParser must not null."); + napi_close_handle_scope(env, scope); return EINVAL; } - napi_value result = nullptr; + napi_value result; napi_call_function(env, value, method, argv.size(), argv.data(), &result); if (!param->retParser(env, handleEscape.Escape(result))) { HILOGI("Parser js result fail."); + napi_close_handle_scope(env, scope); return EINVAL; } + napi_close_handle_scope(env, scope); return ERR_OK; } -- Gitee