From 4dc6f4adf48e9b1d35ff88e30dfbdc016d6621f7 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 16 Nov 2013 20:05:42 +0100 Subject: [PATCH] src: fix MakeCallback() handle leak Create a new HandleScope before looking up the object context with v8::Object::CreationContext(), else we leak the Local 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. --- src/node.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node.cc b/src/node.cc index cd0c32f234..18d23e2713 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1150,10 +1150,10 @@ Handle MakeCallback(Handle recv, const char* method, int argc, Handle argv[]) { + HandleScope handle_scope(node_isolate); // FIXME(bnoordhuis) Isolate-ify. Local 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 MakeCallback(Handle recv, Handle symbol, int argc, Handle argv[]) { + HandleScope handle_scope(node_isolate); // FIXME(bnoordhuis) Isolate-ify. Local 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 MakeCallback(Handle recv, Handle callback, int argc, Handle argv[]) { + HandleScope handle_scope(node_isolate); // FIXME(bnoordhuis) Isolate-ify. Local 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(), callback, argc, argv)); }