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: segfaults when used with worker_threads #193

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"elliptic": "^6.5.4",
"node-addon-api": "^2.0.0",
"node-addon-api": "^3.2.1",
"node-gyp-build": "^4.2.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/secp256k1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
} while (0)

// Secp256k1
Napi::FunctionReference Secp256k1Addon::constructor;
unsigned int Secp256k1Addon::secp256k1_context_flags =
const unsigned int Secp256k1Addon::secp256k1_context_flags =
SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY;

Napi::Value Secp256k1Addon::Init(Napi::Env env) {
Expand Down Expand Up @@ -66,8 +65,9 @@ Napi::Value Secp256k1Addon::Init(Napi::Env env) {
InstanceMethod("ecdh", &Secp256k1Addon::ECDH),
});

constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
env.SetInstanceData<Napi::FunctionReference>(constructor);

return func;
}
Expand Down
3 changes: 1 addition & 2 deletions src/secp256k1.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class Secp256k1Addon : public Napi::ObjectWrap<Secp256k1Addon> {
};

private:
static Napi::FunctionReference constructor;
static unsigned int secp256k1_context_flags;
static const unsigned int secp256k1_context_flags;
const secp256k1_context* ctx_;
ECDSASignData ecdsa_sign_data;
ECDHData ecdh_data;
Expand Down