summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-04-15 09:05:48 -0700
committerRichard Lau <rlau@redhat.com>2022-03-30 10:49:08 -0400
commite707514c80371971027cd42682931f171aedd125 (patch)
tree75bb36be685c66a63abd0f90abfe7e8313a37467
parent81b4dc88f18f7196c36fd40be6494e602882bf50 (diff)
downloadnode-new-e707514c80371971027cd42682931f171aedd125.tar.gz
src: fix finalization crash
PR-URL: https://github.com/nodejs/node/pull/38250 Backport-PR-URL: https://github.com/nodejs/node/pull/42512 Fixes: https://github.com/nodejs/node/issues/38040 Reviewed-By: Beth Griggs <bgriggs@redhat.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
-rw-r--r--src/js_native_api_v8.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc
index 8254dc7d6c..81619b9141 100644
--- a/src/js_native_api_v8.cc
+++ b/src/js_native_api_v8.cc
@@ -379,6 +379,9 @@ class Reference : public RefBase {
protected:
inline void Finalize(bool is_env_teardown = false) override {
+ if (is_env_teardown) env_teardown_finalize_started_ = true;
+ if (!is_env_teardown && env_teardown_finalize_started_) return;
+
// 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
// `RefBase::Finalize()`. ClearWeak will ensure that even if the
@@ -467,6 +470,7 @@ class Reference : public RefBase {
reference->Finalize();
}
+ bool env_teardown_finalize_started_ = false;
v8impl::Persistent<v8::Value> _persistent;
SecondPassCallParameterRef* _secondPassParameter;
};