Browse Source

lib,src: reset zero fill flag on exception

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: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
v7.x
Ben Noordhuis 9 years ago
parent
commit
3a3996315c
  1. 11
      lib/buffer.js
  2. 2
      src/node.cc

11
lib/buffer.js

@ -65,8 +65,15 @@ const zeroFill = bindingObj.zeroFill || [0];
function createBuffer(size, noZeroFill) { function createBuffer(size, noZeroFill) {
if (noZeroFill) if (noZeroFill)
zeroFill[0] = 0; // Reset by the runtime. zeroFill[0] = 0;
const ui8 = new Uint8Array(size);
try {
var ui8 = new Uint8Array(size);
} finally {
if (noZeroFill)
zeroFill[0] = 1;
}
Object.setPrototypeOf(ui8, Buffer.prototype); Object.setPrototypeOf(ui8, Buffer.prototype);
return ui8; return ui8;
} }

2
src/node.cc

@ -973,7 +973,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
void* ArrayBufferAllocator::Allocate(size_t size) { void* ArrayBufferAllocator::Allocate(size_t size) {
if (zero_fill_field_ || zero_fill_all_buffers) if (zero_fill_field_ || zero_fill_all_buffers)
return calloc(size, 1); return calloc(size, 1);
zero_fill_field_ = 1; else
return malloc(size); return malloc(size);
} }

Loading…
Cancel
Save