Browse Source

src: fix handle leak in UDPWrap::Instantiate()

Create a handle scope before performing a check that creates a handle,
otherwise the handle is leaked into the handle scope of the caller.

PR-URL: https://github.com/nodejs/node/pull/7711
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
v7.x
Ben Noordhuis 8 years ago
parent
commit
4e989b00a3
  1. 2
      src/udp_wrap.cc

2
src/udp_wrap.cc

@ -436,9 +436,9 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
Local<Object> UDPWrap::Instantiate(Environment* env, AsyncWrap* parent) {
EscapableHandleScope scope(env->isolate());
// If this assert fires then Initialize hasn't been called yet.
CHECK_EQ(env->udp_constructor_function().IsEmpty(), false);
EscapableHandleScope scope(env->isolate());
Local<Value> ptr = External::New(env->isolate(), parent);
return scope.Escape(env->udp_constructor_function()
->NewInstance(env->context(), 1, &ptr).ToLocalChecked());

Loading…
Cancel
Save