Skip to content

Commit 2c8b9e4

Browse files
authored
Fix MyObject memory leak in some napi examples (#589)
1 parent 92a4254 commit 2c8b9e4

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/1-getting-started/6_object_wrap/napi/myobject.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ MyObject::~MyObject() {
1111
void MyObject::Destructor(napi_env env,
1212
void* nativeObject,
1313
void* /*finalize_hint*/) {
14-
reinterpret_cast<MyObject*>(nativeObject)->~MyObject();
14+
delete reinterpret_cast<MyObject*>(nativeObject);
1515
}
1616

1717
#define DECLARE_NAPI_METHOD(name, func) \

src/1-getting-started/7_factory_wrap/napi/myobject.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MyObject::~MyObject() {
1010
void MyObject::Destructor(napi_env env,
1111
void* nativeObject,
1212
void* /*finalize_hint*/) {
13-
reinterpret_cast<MyObject*>(nativeObject)->~MyObject();
13+
delete reinterpret_cast<MyObject*>(nativeObject);
1414
}
1515

1616
#define DECLARE_NAPI_METHOD(name, func) \

src/2-js-to-native-conversion/8_passing_wrapped/napi/myobject.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MyObject::~MyObject() {
1010
void MyObject::Destructor(napi_env env,
1111
void* nativeObject,
1212
void* /*finalize_hint*/) {
13-
reinterpret_cast<MyObject*>(nativeObject)->~MyObject();
13+
delete reinterpret_cast<MyObject*>(nativeObject);
1414
}
1515

1616
napi_status MyObject::Init(napi_env env) {

0 commit comments

Comments
 (0)