Skip to content

Commit

Permalink
Fix MyObject memory leak in some napi examples (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm authored Feb 7, 2025
1 parent 92a4254 commit 2c8b9e4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/1-getting-started/6_object_wrap/napi/myobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MyObject::~MyObject() {
void MyObject::Destructor(napi_env env,
void* nativeObject,
void* /*finalize_hint*/) {
reinterpret_cast<MyObject*>(nativeObject)->~MyObject();
delete reinterpret_cast<MyObject*>(nativeObject);
}

#define DECLARE_NAPI_METHOD(name, func) \
Expand Down
2 changes: 1 addition & 1 deletion src/1-getting-started/7_factory_wrap/napi/myobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MyObject::~MyObject() {
void MyObject::Destructor(napi_env env,
void* nativeObject,
void* /*finalize_hint*/) {
reinterpret_cast<MyObject*>(nativeObject)->~MyObject();
delete reinterpret_cast<MyObject*>(nativeObject);
}

#define DECLARE_NAPI_METHOD(name, func) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MyObject::~MyObject() {
void MyObject::Destructor(napi_env env,
void* nativeObject,
void* /*finalize_hint*/) {
reinterpret_cast<MyObject*>(nativeObject)->~MyObject();
delete reinterpret_cast<MyObject*>(nativeObject);
}

napi_status MyObject::Init(napi_env env) {
Expand Down

0 comments on commit 2c8b9e4

Please sign in to comment.