Skip to content

Commit 7aa2689

Browse files
bnoordhuisMylesBorins
authored andcommittedOct 26, 2016
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: #7711 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent c841b5a commit 7aa2689

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎src/node_buffer.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ MaybeLocal<Object> New(Environment* env, size_t length) {
298298

299299

300300
MaybeLocal<Object> Copy(Isolate* isolate, const char* data, size_t length) {
301+
EscapableHandleScope handle_scope(isolate);
301302
Environment* env = Environment::GetCurrent(isolate);
302-
EscapableHandleScope handle_scope(env->isolate());
303303
Local<Object> obj;
304304
if (Buffer::Copy(env, data, length).ToLocal(&obj))
305305
return handle_scope.Escape(obj);
@@ -348,8 +348,8 @@ MaybeLocal<Object> New(Isolate* isolate,
348348
size_t length,
349349
FreeCallback callback,
350350
void* hint) {
351+
EscapableHandleScope handle_scope(isolate);
351352
Environment* env = Environment::GetCurrent(isolate);
352-
EscapableHandleScope handle_scope(env->isolate());
353353
Local<Object> obj;
354354
if (Buffer::New(env, data, length, callback, hint).ToLocal(&obj))
355355
return handle_scope.Escape(obj);
@@ -382,8 +382,8 @@ MaybeLocal<Object> New(Environment* env,
382382

383383

384384
MaybeLocal<Object> New(Isolate* isolate, char* data, size_t length) {
385+
EscapableHandleScope handle_scope(isolate);
385386
Environment* env = Environment::GetCurrent(isolate);
386-
EscapableHandleScope handle_scope(env->isolate());
387387
Local<Object> obj;
388388
if (Buffer::New(env, data, length).ToLocal(&obj))
389389
return handle_scope.Escape(obj);

0 commit comments

Comments
 (0)
Please sign in to comment.