summaryrefslogtreecommitdiff
path: root/src/node_api.cc
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2018-06-04 19:20:54 -0400
committerGabriel Schulhof <gabriel.schulhof@intel.com>2018-06-06 09:36:06 -0400
commit991f4060adf1800ef50eaaf8bd84ef42e7587f08 (patch)
tree29228163b628dc150981a80e6068e0df0e028d94 /src/node_api.cc
parent1aa582a97c4d8974b5ce2a3435fb07f01792af5b (diff)
downloadandroid-node-v8-991f4060adf1800ef50eaaf8bd84ef42e7587f08.tar.gz
android-node-v8-991f4060adf1800ef50eaaf8bd84ef42e7587f08.tar.bz2
android-node-v8-991f4060adf1800ef50eaaf8bd84ef42e7587f08.zip
n-api: back up env before async work finalize
We must back up the value of `_env` before calling the async work complete callback, because the complete callback may delete the instance in which `_env` is stored by calling `napi_delete_async_work`, and because we need to use it after the complete callback has completed. Fixes: https://github.com/nodejs/node/issues/20966 PR-URL: https://github.com/nodejs/node/pull/21129 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'src/node_api.cc')
-rw-r--r--src/node_api.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/node_api.cc b/src/node_api.cc
index a83244131f..fdd12afc22 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -3393,13 +3393,19 @@ class Work : public node::AsyncResource, public node::ThreadPoolWork {
CallbackScope callback_scope(this);
- NAPI_CALL_INTO_MODULE(_env,
+ // We have to back up the env here because the `NAPI_CALL_INTO_MODULE` macro
+ // makes use of it after the call into the module completes, but the module
+ // may have deallocated **this**, and along with it the place where _env is
+ // stored.
+ napi_env env = _env;
+
+ NAPI_CALL_INTO_MODULE(env,
_complete(_env, ConvertUVErrorCode(status), _data),
- [this] (v8::Local<v8::Value> local_err) {
+ [env] (v8::Local<v8::Value> local_err) {
// If there was an unhandled exception in the complete callback,
// report it as a fatal exception. (There is no JavaScript on the
// callstack that can possibly handle it.)
- v8impl::trigger_fatal_exception(_env, local_err);
+ v8impl::trigger_fatal_exception(env, local_err);
});
// Note: Don't access `work` after this point because it was