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

Cleanup vm module memory leakage #3090

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions src/node_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,24 +348,25 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
display_error = true;
}

Persistent<Context> context;
Handle<Context> context = Context::GetCurrent();

Local<Array> keys;
if (context_flag == newContext) {
// Create the new context
context = Context::New();
Persistent<Context> tmp = Context::New();
context = Local<Context>::New(tmp);
tmp.Dispose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here explaining why the code looks like that?


} else if (context_flag == userContext) {
// Use the passed in context
WrappedContext *nContext = ObjectWrap::Unwrap<WrappedContext>(sandbox);
context = nContext->GetV8Context();
}

Context::Scope context_scope(context);

// New and user context share code. DRY it up.
if (context_flag == userContext || context_flag == newContext) {
// Enter the context
context->Enter();

// Copy everything from the passed in sandbox (either the persistent
// context for runInContext(), or the sandbox arg to runInNewContext()).
CloneObject(args.This(), sandbox, context->Global()->GetPrototype());
Expand Down Expand Up @@ -407,11 +408,6 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
if (output_flag == returnResult) {
result = script->Run();
if (result.IsEmpty()) {
if (context_flag == newContext) {
context->DetachGlobal();
context->Exit();
context.Dispose();
}
return try_catch.ReThrow();
}
} else {
Expand All @@ -429,16 +425,6 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
CloneObject(args.This(), context->Global()->GetPrototype(), sandbox);
}

if (context_flag == newContext) {
// Clean up, clean up, everybody everywhere!
context->DetachGlobal();
context->Exit();
context.Dispose();
} else if (context_flag == userContext) {
// Exit the passed in context.
context->Exit();
}

return result == args.This() ? result : scope.Close(result);
}

Expand Down