Skip to content

Commit

Permalink
lib,src: reset zero fill flag on exception
Browse files Browse the repository at this point in the history
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: #7093
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis committed Jun 2, 2016
1 parent 3549a5e commit 3a39963
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,8 @@ Local<Value> 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,
Expand Down

0 comments on commit 3a39963

Please sign in to comment.