Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix severe node performance issue due to buffer allocation bug, fix undefined behavior which breaks node > 18.7.0 #82

Open
wants to merge 3 commits into
base: latest
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle case where the previously allocated array buffer is shorter th…
…an the current request. This is likely what drove the problematic max size allocation
doggkruse authored and afreer committed Sep 19, 2023
commit f8a991c7b019379d6cfcbb6319e39b41d5934164
4 changes: 2 additions & 2 deletions src/binding.cc
Original file line number Diff line number Diff line change
@@ -105,12 +105,12 @@ class InstanceData final : public RefNapi::Instance {

auto it = pointer_to_orig_buffer.find(ptr);
if (it != pointer_to_orig_buffer.end()) {
it->second.finalizer_count++;
if (!it->second.ab.Value().IsEmpty()) {
// Already have a valid entry, nothing to do.
return;
}
it->second.ab.Reset(buf, 0);
it->second.finalizer_count++;
} else {
pointer_to_orig_buffer.emplace(ptr, ArrayBufferEntry {
Reference<ArrayBuffer>::New(buf, 0),
@@ -140,7 +140,7 @@ class InstanceData final : public RefNapi::Instance {
if (it != pointer_to_orig_buffer.end())
ab = it->second.ab.Value();

if (ab.IsEmpty()) {
if (ab.IsEmpty() || (ab.ByteLength() < length)) {
length = std::min<size_t>(length, kMaxLength);
ab = Buffer<char>::New(env, ptr, length, [this](Env env, char* ptr) {
UnregisterArrayBuffer(ptr);