From 3a3996315c39b377d19db03434acf27d1d83cb98 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 1 Jun 2016 15:53:01 +0200 Subject: [PATCH] lib,src: reset zero fill flag on exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exceptions thrown from the Uint8Array constructor would leave it disabled. Regression introduced in commit 27e84dd ("lib,src: clean up ArrayBufferAllocator") from two days ago. A follow-up commit will add a regression test. PR-URL: https://github.com/nodejs/node/pull/7093 Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell Reviewed-By: Trevor Norris --- lib/buffer.js | 11 +++++++++-- src/node.cc | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) 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,