Skip to content

Commit 2aa9ca1

Browse files
mhdawsonrichardlau
authored andcommittedMar 30, 2022
node-api: fix crash in finalization
Refs: nodejs/node-addon-api#906 Refs: #37616 Fix crash introduced by #37616 Signed-off-by: Michael Dawson <mdawson@devrus.com> PR-URL: #37876 Backport-PR-URL: #42512 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a2f4206 commit 2aa9ca1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

Diff for: ‎src/js_native_api_v8.cc

+5-2
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)
Please sign in to comment.