diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index f5d622fc255cdf..4e039d5dbf2d37 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -115,6 +115,7 @@ HandleWrap::HandleWrap(Environment* env, void HandleWrap::OnClose(uv_handle_t* handle) { + CHECK_NOT_NULL(handle->data); BaseObjectPtr wrap { static_cast(handle->data) }; wrap->Detach(); diff --git a/src/node_messaging.cc b/src/node_messaging.cc index c7c46063731a5b..2de1c824d206d2 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -515,10 +515,9 @@ MessagePort::MessagePort(Environment* env, CHECK_EQ(uv_async_init(env->event_loop(), &async_, onmessage), 0); - async_.data = nullptr; // Reset later to indicate success of the constructor. - auto cleanup = OnScopeLeave([&]() { - if (async_.data == nullptr) Close(); - }); + // Reset later to indicate success of the constructor. + bool succeeded = false; + auto cleanup = OnScopeLeave([&]() { if (!succeeded) Close(); }); Local fn; if (!wrap->Get(context, env->oninit_symbol()).ToLocal(&fn)) @@ -535,7 +534,7 @@ MessagePort::MessagePort(Environment* env, return; emit_message_fn_.Reset(env->isolate(), emit_message_fn); - async_.data = static_cast(this); + succeeded = true; Debug(this, "Created message port"); }