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 <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Ali Ijaz Sheikh 2017-10-24 22:24:28 -07:00
parent e8de2bfd13
commit e3503aca08
2 changed files with 9 additions and 4 deletions

View File

@ -306,7 +306,7 @@ inline Environment::Environment(IsolateData* isolate_data,
emit_napi_warning_(true), emit_napi_warning_(true),
makecallback_cntr_(0), makecallback_cntr_(0),
#if HAVE_INSPECTOR #if HAVE_INSPECTOR
inspector_agent_(this), inspector_agent_(new inspector::Agent(this)),
#endif #endif
handle_cleanup_waiting_(0), handle_cleanup_waiting_(0),
http_parser_buffer_(nullptr), http_parser_buffer_(nullptr),
@ -347,6 +347,11 @@ inline Environment::Environment(IsolateData* isolate_data,
inline Environment::~Environment() { inline Environment::~Environment() {
v8::HandleScope handle_scope(isolate()); v8::HandleScope handle_scope(isolate());
#if HAVE_INSPECTOR
// Destroy inspector agent before erasing the context.
delete inspector_agent_;
#endif
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
nullptr); nullptr);
#define V(PropertyName, TypeName) PropertyName ## _.Reset(); #define V(PropertyName, TypeName) PropertyName ## _.Reset();

View File

@ -667,8 +667,8 @@ class Environment {
#undef V #undef V
#if HAVE_INSPECTOR #if HAVE_INSPECTOR
inline inspector::Agent* inspector_agent() { inline inspector::Agent* inspector_agent() const {
return &inspector_agent_; return inspector_agent_;
} }
#endif #endif
@ -713,7 +713,7 @@ class Environment {
std::map<std::string, uint64_t> performance_marks_; std::map<std::string, uint64_t> performance_marks_;
#if HAVE_INSPECTOR #if HAVE_INSPECTOR
inspector::Agent inspector_agent_; inspector::Agent* const inspector_agent_;
#endif #endif
HandleWrapQueue handle_wrap_queue_; HandleWrapQueue handle_wrap_queue_;