diff --git a/lib/buffer.js b/lib/buffer.js index 54096aa99410c1..f45fe2dad954d2 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -65,8 +65,15 @@ const zeroFill = bindingObj.zeroFill || [0]; function createBuffer(size, noZeroFill) { if (noZeroFill) - zeroFill[0] = 0; // Reset by the runtime. - const ui8 = new Uint8Array(size); + zeroFill[0] = 0; + + try { + var ui8 = new Uint8Array(size); + } finally { + if (noZeroFill) + zeroFill[0] = 1; + } + Object.setPrototypeOf(ui8, Buffer.prototype); return ui8; } diff --git a/src/node.cc b/src/node.cc index 3c508183c922d8..10d67a02fc92e2 100644 --- a/src/node.cc +++ b/src/node.cc @@ -973,8 +973,8 @@ Local WinapiErrnoException(Isolate* isolate, void* ArrayBufferAllocator::Allocate(size_t size) { if (zero_fill_field_ || zero_fill_all_buffers) return calloc(size, 1); - zero_fill_field_ = 1; - return malloc(size); + else + return malloc(size); } static bool DomainHasErrorHandler(const Environment* env,