Skip to content

Commit 8193f14

Browse files
doggkrusedfreer-tandem
authored andcommitted
Change to using std::min() when allocating Buffers on the C++ side. This will result in Buffers being allocated to the size requested up to kMaxLength (0x3fffffff) instead of the current behavior of always allocating kMaxLength. Since these buffers are allocated in the node external memory (limited to 64M) the old behavior would very quickly cause massive GC pressure as the GC is triggered on each new Buffer allocation once the node external memory limit is reached. It appears the old behavior was not intentional and should have always been std::min(). This should fix node-ffi-napi#72
1 parent a7f62a4 commit 8193f14

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/binding.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class InstanceData final : public RefNapi::Instance {
141141
ab = it->second.ab.Value();
142142

143143
if (ab.IsEmpty()) {
144-
length = std::max<size_t>(length, kMaxLength);
144+
length = std::min<size_t>(length, kMaxLength);
145145
ab = Buffer<char>::New(env, ptr, length, [this](Env env, char* ptr) {
146146
UnregisterArrayBuffer(ptr);
147147
}).ArrayBuffer();

0 commit comments

Comments
 (0)