Skip to content

Commit 6754bae

Browse files
committed
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: nodejs#7711 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent c897d0b commit 6754bae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/node_buffer.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ MaybeLocal<Object> New(Environment* env, size_t length) {
345345

346346

347347
MaybeLocal<Object> Copy(Isolate* isolate, const char* data, size_t length) {
348+
EscapableHandleScope handle_scope(isolate);
348349
Environment* env = Environment::GetCurrent(isolate);
349-
EscapableHandleScope handle_scope(env->isolate());
350350
Local<Object> obj;
351351
if (Buffer::Copy(env, data, length).ToLocal(&obj))
352352
return handle_scope.Escape(obj);
@@ -395,8 +395,8 @@ MaybeLocal<Object> New(Isolate* isolate,
395395
size_t length,
396396
FreeCallback callback,
397397
void* hint) {
398+
EscapableHandleScope handle_scope(isolate);
398399
Environment* env = Environment::GetCurrent(isolate);
399-
EscapableHandleScope handle_scope(env->isolate());
400400
Local<Object> obj;
401401
if (Buffer::New(env, data, length, callback, hint).ToLocal(&obj))
402402
return handle_scope.Escape(obj);
@@ -434,8 +434,8 @@ MaybeLocal<Object> New(Environment* env,
434434

435435

436436
MaybeLocal<Object> New(Isolate* isolate, char* data, size_t length) {
437+
EscapableHandleScope handle_scope(isolate);
437438
Environment* env = Environment::GetCurrent(isolate);
438-
EscapableHandleScope handle_scope(env->isolate());
439439
Local<Object> obj;
440440
if (Buffer::New(env, data, length).ToLocal(&obj))
441441
return handle_scope.Escape(obj);

0 commit comments

Comments
 (0)