From 6754bae82f97bd2df9b67faf5e8763108cf51925 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 13 Jul 2016 16:06:18 +0200 Subject: [PATCH] src: fix handle leak in Buffer::New() Fix handle leaks in Buffer::New() and Buffer::Copy() by creating the handle scope before looking up the env with Environment::GetCurrent(). Environment::GetCurrent() calls v8::Isolate::GetCurrentContext(), which creates a handle in the current scope, i.e., the scope created by the caller of Buffer::New() or Buffer::Copy(). PR-URL: https://github.com/nodejs/node/pull/7711 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Trevor Norris --- src/node_buffer.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index e88dd1e661..d86968ebab 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -345,8 +345,8 @@ MaybeLocal New(Environment* env, size_t length) { MaybeLocal Copy(Isolate* isolate, const char* data, size_t length) { + EscapableHandleScope handle_scope(isolate); Environment* env = Environment::GetCurrent(isolate); - EscapableHandleScope handle_scope(env->isolate()); Local obj; if (Buffer::Copy(env, data, length).ToLocal(&obj)) return handle_scope.Escape(obj); @@ -395,8 +395,8 @@ MaybeLocal New(Isolate* isolate, size_t length, FreeCallback callback, void* hint) { + EscapableHandleScope handle_scope(isolate); Environment* env = Environment::GetCurrent(isolate); - EscapableHandleScope handle_scope(env->isolate()); Local obj; if (Buffer::New(env, data, length, callback, hint).ToLocal(&obj)) return handle_scope.Escape(obj); @@ -434,8 +434,8 @@ MaybeLocal New(Environment* env, MaybeLocal New(Isolate* isolate, char* data, size_t length) { + EscapableHandleScope handle_scope(isolate); Environment* env = Environment::GetCurrent(isolate); - EscapableHandleScope handle_scope(env->isolate()); Local obj; if (Buffer::New(env, data, length).ToLocal(&obj)) return handle_scope.Escape(obj);