Skip to content

Commit

Permalink
node-api,test: fix test_reference_double_free crash
Browse files Browse the repository at this point in the history
PR-URL: #44927
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
vmoroz authored and RafaelGSS committed Nov 10, 2022
1 parent 8662399 commit 2105f09
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,22 @@ static napi_value New(napi_env env, napi_callback_info info) {

static void NoopDeleter(napi_env env, void* data, void* hint) {}

static void DeleteImmediately(napi_env env, napi_callback_info info) {
static napi_value DeleteImmediately(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value js_obj;
napi_ref ref;
napi_valuetype type;

NODE_API_CALL_RETURN_VOID(env,
napi_get_cb_info(env, info, &argc, &js_obj, NULL, NULL));
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, &js_obj, NULL, NULL));

napi_valuetype type;
NODE_API_CALL_RETURN_VOID(env, napi_typeof(env, js_obj, &type));
NODE_API_CALL(env, napi_typeof(env, js_obj, &type));
NODE_API_ASSERT(env, type == napi_object, "Expected object parameter");

NODE_API_CALL(env, napi_wrap(env, js_obj, NULL, NoopDeleter, NULL, &ref));
NODE_API_CALL(env, napi_delete_reference(env, ref));
NODE_API_CALL(env, napi_remove_wrap(env, js_obj, NULL));

NODE_API_CALL_RETURN_VOID(env,
napi_wrap(env, js_obj, NULL, NoopDeleter, NULL, &ref));
NODE_API_CALL_RETURN_VOID(env, napi_delete_reference(env, ref));
NODE_API_CALL_RETURN_VOID(env, napi_remove_wrap(env, js_obj, NULL));
return NULL;
}

EXTERN_C_START
Expand Down

0 comments on commit 2105f09

Please sign in to comment.