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

buffer: fix assertion error in WeakCallback #3329

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
...
  • Loading branch information
indutny committed Oct 12, 2015
commit a0569882c813e6910b92c4584a2dd6811f21809e
3 changes: 2 additions & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ void CallbackInfo::WeakCallback(Isolate* isolate, Local<Object> object) {
Local<ArrayBuffer> buf = object.As<ArrayBuffer>();
ArrayBuffer::Contents obj_c = buf->GetContents();
char* const obj_data = static_cast<char*>(obj_c.Data());
CHECK_NE(obj_data, nullptr);
if (buf->ByteLength() != 0)
CHECK_NE(obj_data, nullptr);

buf->Neuter();
callback_(obj_data, hint_);
Expand Down
2 changes: 1 addition & 1 deletion test/addons/buffer-free-callback/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Alloc(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(node::Buffer::New(
isolate,
buf,
sizeof(buf),
args[0]->IntegerValue(),
FreeCallback,
nullptr).ToLocalChecked());
}
Expand Down
25 changes: 17 additions & 8 deletions test/addons/buffer-free-callback/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
require('../../common');
var assert = require('assert');
var binding = require('./build/Release/binding');
var buf = binding.alloc();
var slice = buf.slice(32);
buf = null;
binding.check(slice);
slice = null;
gc();
gc();
gc();

function check(size) {
var buf = binding.alloc(size);
var slice = buf.slice(size >>> 1);

buf = null;
binding.check(slice);
slice = null;
gc();
gc();
gc();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear to me why calling gc() three times is required here. @indutny Sorry to pull this up from more than 3 years ago, but do you remember why?

}

check(64);

// Empty ArrayBuffer does not allocate data, worth checking
check(0);