Skip to content

Commit e3503ac

Browse files
committed
src: destroy inspector agent before context
The inspector_agent depends on the context still being accessible during the destructor execution. PR-URL: #16472 Fixes: #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>
1 parent e8de2bf commit e3503ac

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/env-inl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ inline Environment::Environment(IsolateData* isolate_data,
306306
emit_napi_warning_(true),
307307
makecallback_cntr_(0),
308308
#if HAVE_INSPECTOR
309-
inspector_agent_(this),
309+
inspector_agent_(new inspector::Agent(this)),
310310
#endif
311311
handle_cleanup_waiting_(0),
312312
http_parser_buffer_(nullptr),
@@ -347,6 +347,11 @@ inline Environment::Environment(IsolateData* isolate_data,
347347
inline Environment::~Environment() {
348348
v8::HandleScope handle_scope(isolate());
349349

350+
#if HAVE_INSPECTOR
351+
// Destroy inspector agent before erasing the context.
352+
delete inspector_agent_;
353+
#endif
354+
350355
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
351356
nullptr);
352357
#define V(PropertyName, TypeName) PropertyName ## _.Reset();

src/env.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ class Environment {
667667
#undef V
668668

669669
#if HAVE_INSPECTOR
670-
inline inspector::Agent* inspector_agent() {
671-
return &inspector_agent_;
670+
inline inspector::Agent* inspector_agent() const {
671+
return inspector_agent_;
672672
}
673673
#endif
674674

@@ -713,7 +713,7 @@ class Environment {
713713
std::map<std::string, uint64_t> performance_marks_;
714714

715715
#if HAVE_INSPECTOR
716-
inspector::Agent inspector_agent_;
716+
inspector::Agent* const inspector_agent_;
717717
#endif
718718

719719
HandleWrapQueue handle_wrap_queue_;

0 commit comments

Comments
 (0)