Skip to content

Commit 3ab223d

Browse files
mhdawsonruyadorno
authored andcommitted
node-api: fix crash in finalization
Refs: nodejs/node-addon-api#906 Refs: #37616 Fix crash introduced by #37616 Signed-off-by: Michael Dawson <[email protected]> PR-URL: #37876 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 5cdeb76 commit 3ab223d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/js_native_api_v8.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,11 @@ class Reference : public RefBase {
374374
inline void Finalize(bool is_env_teardown = false) override {
375375
// During env teardown, `~napi_env()` alone is responsible for finalizing.
376376
// Thus, we don't want any stray gc passes to trigger a second call to
377-
// `Finalize()`, so let's reset the persistent here.
378-
if (is_env_teardown) _persistent.ClearWeak();
377+
// `Finalize()`, so let's reset the persistent here if nothing is
378+
// keeping it alive.
379+
if (is_env_teardown && _persistent.IsWeak()) {
380+
_persistent.ClearWeak();
381+
}
379382

380383
// Chain up to perform the rest of the finalization.
381384
RefBase::Finalize(is_env_teardown);

0 commit comments

Comments
 (0)