Browse Source

src: fix MakeCallback() handle leak

Create a new HandleScope before looking up the object context with
v8::Object::CreationContext(), else we leak the Local<Context> into
the current HandleScope.

That's relatively harmless unless the HandleScope is long-lived and
MakeCallback() is called a lot.  In a scenario like that, we may end
up leaking a lot of memory.

What is unfortunate about this change is that we're trying hard to
eradicate the node_isolate global.  Longer term, we will probably have
to change the MakeCallback() prototype to one that requires an explicit
v8::Isolate* argument.
v0.11.12-release
Ben Noordhuis 11 years ago
committed by Timothy J Fontaine
parent
commit
4dc6f4adf4
  1. 6
      src/node.cc

6
src/node.cc

@ -1150,10 +1150,10 @@ Handle<Value> MakeCallback(Handle<Object> recv,
const char* method,
int argc,
Handle<Value> argv[]) {
HandleScope handle_scope(node_isolate); // FIXME(bnoordhuis) Isolate-ify.
Local<Context> context = recv->CreationContext();
Environment* env = Environment::GetCurrent(context);
Context::Scope context_scope(context);
HandleScope handle_scope(env->isolate());
return handle_scope.Close(MakeCallback(env, recv, method, argc, argv));
}
@ -1162,10 +1162,10 @@ Handle<Value> MakeCallback(Handle<Object> recv,
Handle<String> symbol,
int argc,
Handle<Value> argv[]) {
HandleScope handle_scope(node_isolate); // FIXME(bnoordhuis) Isolate-ify.
Local<Context> context = recv->CreationContext();
Environment* env = Environment::GetCurrent(context);
Context::Scope context_scope(context);
HandleScope handle_scope(env->isolate());
return handle_scope.Close(MakeCallback(env, recv, symbol, argc, argv));
}
@ -1174,10 +1174,10 @@ Handle<Value> MakeCallback(Handle<Object> recv,
Handle<Function> callback,
int argc,
Handle<Value> argv[]) {
HandleScope handle_scope(node_isolate); // FIXME(bnoordhuis) Isolate-ify.
Local<Context> context = recv->CreationContext();
Environment* env = Environment::GetCurrent(context);
Context::Scope context_scope(context);
HandleScope handle_scope(env->isolate());
return handle_scope.Close(
MakeCallback(env, recv.As<Value>(), callback, argc, argv));
}

Loading…
Cancel
Save