Skip to content

Commit 3a39963

Browse files
committed
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: #7093 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 3549a5e commit 3a39963

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/buffer.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,15 @@ const zeroFill = bindingObj.zeroFill || [0];
6565

6666
function createBuffer(size, noZeroFill) {
6767
if (noZeroFill)
68-
zeroFill[0] = 0; // Reset by the runtime.
69-
const ui8 = new Uint8Array(size);
68+
zeroFill[0] = 0;
69+
70+
try {
71+
var ui8 = new Uint8Array(size);
72+
} finally {
73+
if (noZeroFill)
74+
zeroFill[0] = 1;
75+
}
76+
7077
Object.setPrototypeOf(ui8, Buffer.prototype);
7178
return ui8;
7279
}

src/node.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,8 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
973973
void* ArrayBufferAllocator::Allocate(size_t size) {
974974
if (zero_fill_field_ || zero_fill_all_buffers)
975975
return calloc(size, 1);
976-
zero_fill_field_ = 1;
977-
return malloc(size);
976+
else
977+
return malloc(size);
978978
}
979979

980980
static bool DomainHasErrorHandler(const Environment* env,

0 commit comments

Comments
 (0)