diff --git a/src/env-inl.h b/src/env-inl.h index 5c28b2334bd661..4dadf5ea2c1978 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -326,8 +326,9 @@ inline Environment::~Environment() { v8::HandleScope handle_scope(isolate()); #if HAVE_INSPECTOR - // Destroy inspector agent before erasing the context. - delete inspector_agent_; + // Destroy inspector agent before erasing the context. The inspector + // destructor depends on the context still being accessible. + inspector_agent_.reset(nullptr); #endif context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, diff --git a/src/env.h b/src/env.h index 296fcf4877baba..e37dcf17aeb1d6 100644 --- a/src/env.h +++ b/src/env.h @@ -689,7 +689,7 @@ class Environment { #if HAVE_INSPECTOR inline inspector::Agent* inspector_agent() const { - return inspector_agent_; + return inspector_agent_.get(); } #endif @@ -734,7 +734,7 @@ class Environment { std::map performance_marks_; #if HAVE_INSPECTOR - inspector::Agent* const inspector_agent_; + std::unique_ptr inspector_agent_; #endif HandleWrapQueue handle_wrap_queue_;