diff --git a/src/env-inl.h b/src/env-inl.h index 2cd0046b85475e..71499946f8979d 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -347,8 +347,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 5f424a39fe5b74..7a97ecd3505876 100644 --- a/src/env.h +++ b/src/env.h @@ -673,7 +673,7 @@ class Environment { #if HAVE_INSPECTOR inline inspector::Agent* inspector_agent() const { - return inspector_agent_; + return inspector_agent_.get(); } #endif @@ -718,7 +718,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_;