Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Last active September 18, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooTallNate/e0eb7a55546c25a58990 to your computer and use it in GitHub Desktop.
Save TooTallNate/e0eb7a55546c25a58990 to your computer and use it in GitHub Desktop.
OS X Yosemite / Node.js v4.0.0 / Segfault - See https://github.com/node-ffi/node-ffi/issues/239
#include <node.h>
#include <node_buffer.h>
#include <nan.h>
#include <dlfcn.h>
#include <stdio.h>
using namespace v8;
using namespace node;
/*
* Called when the wrapped pointer is garbage collected.
* We never have to do anything here...
*/
void wrap_pointer_cb(char *data, void *hint) {
//fprintf(stderr, "wrap_pointer_cb\n");
}
/*
* Converts an arbitrary pointer to a node Buffer with 0-length
*/
Local<Value> WrapPointer(char *ptr) {
Nan::EscapableHandleScope scope;
return scope.Escape(Nan::NewBuffer(ptr, 0, wrap_pointer_cb, NULL).ToLocalChecked());
}
NAN_MODULE_INIT(init) {
Nan::HandleScope scope;
// dl functions used by the DynamicLibrary JS class
target->Set(Nan::New<String>("dlopen").ToLocalChecked(), WrapPointer((char *)printf));
target->Set(Nan::New<String>("dlclose").ToLocalChecked(), WrapPointer((char *)dlclose));
target->Set(Nan::New<String>("dlsym").ToLocalChecked(), WrapPointer((char *)dlsym));
target->Set(Nan::New<String>("dlerror").ToLocalChecked(), WrapPointer((char *)dlerror));
}
NODE_MODULE(binding, init)
{
'targets': [
{
'target_name': 'binding',
'sources': [
'binding.cc'
],
'include_dirs': [
'<!(node -e "require(\'nan\')")'
],
}
]
}
{
"name": "node-v4-buffer-segfault-osx",
"version": "1.0.0",
"description": "Reduced test case for weird Node.js v4 segfault on OS X related to Buffer usage in C++",
"main": "t.js",
"repository": {
"type": "git",
"url": "git://gist.github.com/e0eb7a55546c25a58990.git"
},
"license": "MIT"
}
#!/usr/bin/env node --expose-gc
/**
* Run with `--expose-gc` flag.
*/
var b = require('./build/Release/binding');
gc();
// gc() causes a `Segmentation fault: 11` on OS X 10.10.5
@TooTallNate
Copy link
Author

Fixed (a week ago) in nodejs/node#2791.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment