diff options
author | Michael Dawson <mdawson@devrus.com> | 2021-03-23 11:26:18 -0400 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2021-03-24 16:34:44 -0700 |
commit | 42dc4d14cdea833b807003863d6322723faa1da8 (patch) | |
tree | 9a2c2ce5b9deab35a5efda60feb875b19c7159f7 /src/js_native_api_v8.cc | |
parent | f00c2435922a33f9d866846d0b5d12691b148348 (diff) | |
download | node-new-42dc4d14cdea833b807003863d6322723faa1da8.tar.gz |
node-api: fix crash in finalization
Refs: https://github.com/nodejs/node-addon-api/issues/906
Refs: https://github.com/nodejs/node/pull/37616
Fix crash introduced by https://github.com/nodejs/node/pull/37616
Signed-off-by: Michael Dawson <mdawson@devrus.com>
PR-URL: https://github.com/nodejs/node/pull/37876
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>
Diffstat (limited to 'src/js_native_api_v8.cc')
-rw-r--r-- | src/js_native_api_v8.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 602ded2156..664aa2d41b 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -374,8 +374,11 @@ class Reference : public RefBase { inline void Finalize(bool is_env_teardown = false) override { // During env teardown, `~napi_env()` alone is responsible for finalizing. // Thus, we don't want any stray gc passes to trigger a second call to - // `Finalize()`, so let's reset the persistent here. - if (is_env_teardown) _persistent.ClearWeak(); + // `Finalize()`, so let's reset the persistent here if nothing is + // keeping it alive. + if (is_env_teardown && _persistent.IsWeak()) { + _persistent.ClearWeak(); + } // Chain up to perform the rest of the finalization. RefBase::Finalize(is_env_teardown); |