summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2018-03-31 21:37:17 -0400
committerGabriel Schulhof <gabriel.schulhof@intel.com>2018-04-03 09:37:11 -0400
commit1a5a19d6d475578eec355a8b3079b4a96fc77489 (patch)
tree6e8b4652b8326299018a4c646a48dc18e8b91a1a /src
parented86cc570e875b00a6c94839d87027a27ce85932 (diff)
downloadandroid-node-v8-1a5a19d6d475578eec355a8b3079b4a96fc77489.tar.gz
android-node-v8-1a5a19d6d475578eec355a8b3079b4a96fc77489.tar.bz2
android-node-v8-1a5a19d6d475578eec355a8b3079b4a96fc77489.zip
n-api: back up env before finalize
Heed the comment to not use fields of a Reference after calling its finalize callback, because such a call may destroy the Reference. Fixes: https://github.com/nodejs/node/issues/19673 PR-URL: https://github.com/nodejs/node/pull/19718 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_api.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/node_api.cc b/src/node_api.cc
index c5b93db959..73c2e60d29 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -457,9 +457,10 @@ class Reference : private Finalizer {
// Check before calling the finalize callback, because the callback might
// delete it.
bool delete_self = reference->_delete_self;
+ napi_env env = reference->_env;
if (reference->_finalize_callback != nullptr) {
- NAPI_CALL_INTO_MODULE_THROW(reference->_env,
+ NAPI_CALL_INTO_MODULE_THROW(env,
reference->_finalize_callback(
reference->_env,
reference->_finalize_data,