From 465540cc98e3fdc4f06fad8eebd99534caf9626e Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Tue, 24 Oct 2017 22:24:28 -0700 Subject: [PATCH] src: destroy inspector agent before context The inspector_agent depends on the context still being accessible during the destructor execution. PR-URL: https://github.com/nodejs/node/pull/16472 Fixes: https://github.com/nodejs/node/issues/15558 Reviewed-By: Ben Noordhuis Reviewed-By: Franziska Hinkelmann Reviewed-By: Colin Ihrig Reviewed-By: Eugene Ostroukhov Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- src/env-inl.h | 7 ++++++- src/env.h | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 62dc6e1191bcec..e6e189be3dcbab 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -306,7 +306,7 @@ inline Environment::Environment(IsolateData* isolate_data, emit_napi_warning_(true), makecallback_cntr_(0), #if HAVE_INSPECTOR - inspector_agent_(this), + inspector_agent_(new inspector::Agent(this)), #endif handle_cleanup_waiting_(0), http_parser_buffer_(nullptr), @@ -347,6 +347,11 @@ inline Environment::Environment(IsolateData* isolate_data, inline Environment::~Environment() { v8::HandleScope handle_scope(isolate()); +#if HAVE_INSPECTOR + // Destroy inspector agent before erasing the context. + delete inspector_agent_; +#endif + context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, nullptr); #define V(PropertyName, TypeName) PropertyName ## _.Reset(); diff --git a/src/env.h b/src/env.h index 281cb1838fdf9c..42781e8f23c336 100644 --- a/src/env.h +++ b/src/env.h @@ -668,8 +668,8 @@ class Environment { #undef V #if HAVE_INSPECTOR - inline inspector::Agent* inspector_agent() { - return &inspector_agent_; + inline inspector::Agent* inspector_agent() const { + return inspector_agent_; } #endif @@ -714,7 +714,7 @@ class Environment { std::map performance_marks_; #if HAVE_INSPECTOR - inspector::Agent inspector_agent_; + inspector::Agent* const inspector_agent_; #endif HandleWrapQueue handle_wrap_queue_;