From e2c9040995a13704f07ae36728818500c9091689 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 12 Mar 2015 14:19:16 -0700 Subject: [PATCH] src: do not leak handles on debug and exit Ensure HandleScope is created before creating any new handles (which `Context::Scope` and `Environment::GetCurrent` does). PR-URL: https://github.com/iojs/io.js/pull/1133 Reviewed-By: Ben Noordhuis Reviewed-By: Rod Vagg Reviewed-By: Brian White --- src/node.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 22c4a9b1547e60..b2832086d37237 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3195,6 +3195,7 @@ static void DispatchDebugMessagesAsyncCallback(uv_async_t* handle) { if (debugger_running == false) { fprintf(stderr, "Starting debugger agent.\n"); + HandleScope scope(node_isolate); Environment* env = Environment::GetCurrent(node_isolate); Context::Scope context_scope(env->context()); @@ -3603,8 +3604,8 @@ void AtExit(void (*cb)(void* arg), void* arg) { void EmitBeforeExit(Environment* env) { - Context::Scope context_scope(env->context()); HandleScope handle_scope(env->isolate()); + Context::Scope context_scope(env->context()); Local process_object = env->process_object(); Local exit_code = FIXED_ONE_BYTE_STRING(env->isolate(), "exitCode"); Local args[] = {