diff --git a/tooling/agent/heapprofiler_impl.cpp b/tooling/agent/heapprofiler_impl.cpp index ad413fb9373e861394ef27e4a8b51c5dddfce540..f4ec10bb625356d4e947a40843fd1dca7485fcb9 100644 --- a/tooling/agent/heapprofiler_impl.cpp +++ b/tooling/agent/heapprofiler_impl.cpp @@ -313,7 +313,8 @@ void HeapProfilerImpl::Frontend::ResetProfiles() HeapProfilerImpl::~HeapProfilerImpl() { - uv_loop_t *loop = reinterpret_cast(vm_->GetLoop()); +#if defined(ECMASCRIPT_SUPPORT_HEAPPROFILER) + uv_loop_t *loop = handle_->loop; if (loop != nullptr) { uv_close(reinterpret_cast(handle_), [](uv_handle_t* handle) { if (handle != nullptr) { @@ -321,7 +322,10 @@ HeapProfilerImpl::~HeapProfilerImpl() handle = nullptr; } }); + } else { + delete handle_; } +#endif } DispatchResponse HeapProfilerImpl::AddInspectedHeapObject([[maybe_unused]] const AddInspectedHeapObjectParams ¶ms) @@ -407,6 +411,13 @@ DispatchResponse HeapProfilerImpl::StartTrackingHeapObjects(const StartTrackingH return DispatchResponse::Fail("Loop is nullptr"); } handle_->data = this; + if (((int)handle_->type & UV_TIMER) != UV_TIMER) { + if (loop != nullptr) { + uv_timer_init(loop, handle_); + } else { + return DispatchResponse::Fail("Loop is nullptr"); + } + } uv_timer_start(handle_, HeapTrackingCallback, 0, INTERVAL * MILLI_TO_MICRO); if (DebuggerApi::IsMainThread()) { uv_async_send(&loop->wq_async); diff --git a/tooling/agent/heapprofiler_impl.h b/tooling/agent/heapprofiler_impl.h index 7fe7f153ba008782381f68cf54da842052b225f4..18376a51cfc7bae47f8c92d7a6db36af46e65b17 100644 --- a/tooling/agent/heapprofiler_impl.h +++ b/tooling/agent/heapprofiler_impl.h @@ -41,8 +41,9 @@ public: : vm_(vm), frontend_(channel), stream_(&frontend_) { #if defined(ECMASCRIPT_SUPPORT_HEAPPROFILER) - handle_ = new uv_timer_t; uv_loop_t *loop = reinterpret_cast(vm_->GetLoop()); + handle_ = new uv_timer_t; + handle_->loop = nullptr; if (loop != nullptr) { uv_timer_init(loop, handle_); }