From e57ab7ba06e079eb15c97b228d3fbee2a1514d9b Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sat, 18 Jan 2014 22:49:33 +0000 Subject: [PATCH] node: `EmitExit` should not call `exit()` Before this commit `RunAtExit` and `env->Dispose()` were never reached, because `EmitExit` was always colling `exit`. --- src/env-inl.h | 2 ++ src/node.cc | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 21075a68c26..ef6b3be74a8 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -190,6 +190,8 @@ inline Environment::Environment(v8::Local context) } inline Environment::~Environment() { + v8::HandleScope handle_scope(isolate()); + context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL); #define V(PropertyName, TypeName) PropertyName ## _.Dispose(); ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) diff --git a/src/node.cc b/src/node.cc index 25283c0dcaf..47ef87b77f1 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3315,7 +3315,7 @@ void AtExit(void (*cb)(void* arg), void* arg) { } -void EmitExit(Environment* env) { +int EmitExit(Environment* env) { // process.emit('exit') HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); @@ -3332,7 +3332,7 @@ void EmitExit(Environment* env) { }; MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args); - exit(code); + return code; } @@ -3406,6 +3406,7 @@ int Start(int argc, char** argv) { V8::SetEntropySource(crypto::EntropySource); #endif + int code; V8::Initialize(); { Locker locker(node_isolate); @@ -3417,7 +3418,7 @@ int Start(int argc, char** argv) { // be removed. Context::Scope context_scope(env->context()); uv_run(env->event_loop(), UV_RUN_DEFAULT); - EmitExit(env); + code = EmitExit(env); RunAtExit(env); env->Dispose(); env = NULL; @@ -3431,7 +3432,7 @@ int Start(int argc, char** argv) { delete[] exec_argv; exec_argv = NULL; - return 0; + return code; }