Skip to content

Commit 2aa9ca1

Browse files
mhdawsonrichardlau
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 Backport-PR-URL: #42512 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 a2f4206 commit 2aa9ca1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/js_native_api_v8.cc

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

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

0 commit comments

Comments
 (0)