Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
vm: use MakeWeak to fix leaking contexts
Browse files Browse the repository at this point in the history
This is always something you should do when using `SetHiddenValue`,
apparently. Fixes #6115. Thanks @tjfontaine for the tips.
  • Loading branch information
domenic authored and bnoordhuis committed Aug 28, 2013
1 parent a54f65c commit a3bf3d1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::None;
using v8::Object;
Expand Down Expand Up @@ -62,6 +63,8 @@ class ContextifyContext {
Local<Context> v8_context = CreateV8Context();
context_.Reset(node_isolate, v8_context);
proxy_global_.Reset(node_isolate, v8_context->Global());
sandbox_.MakeWeak(this, SandboxFreeCallback);
sandbox_.MarkIndependent();
}


Expand Down Expand Up @@ -127,10 +130,18 @@ class ContextifyContext {
}
Local<Object> sandbox = args[0].As<Object>();

Local<External> context = External::New(new ContextifyContext(sandbox));
ContextifyContext* context = new ContextifyContext(sandbox);
Local<External> hidden_context = External::New(context);
Local<String> hidden_name =
FIXED_ONE_BYTE_STRING(node_isolate, "_contextifyHidden");
sandbox->SetHiddenValue(hidden_name, context);
sandbox->SetHiddenValue(hidden_name, hidden_context);
}


static void SandboxFreeCallback(Isolate* isolate,
Persistent<Object>* target,
ContextifyContext* context) {
delete context;
}


Expand Down

0 comments on commit a3bf3d1

Please sign in to comment.