diff --git a/packages/profiling-node/bindings/cpu_profiler.cc b/packages/profiling-node/bindings/cpu_profiler.cc index 00996db9e8c9..a3756a92b39c 100644 --- a/packages/profiling-node/bindings/cpu_profiler.cc +++ b/packages/profiling-node/bindings/cpu_profiler.cc @@ -111,15 +111,9 @@ class MeasurementsTicker { size_t listener_count(); - ~MeasurementsTicker() { + void Cleanup() { uv_timer_stop(&timer); - - auto handle = reinterpret_cast(&timer); - - // Calling uv_close on an inactive handle will cause a segfault. - if (uv_is_active(handle)) { - uv_close(handle, nullptr); - } + uv_close(reinterpret_cast(&timer), nullptr); } }; @@ -1155,6 +1149,7 @@ void FreeAddonData(napi_env env, void *data, void *hint) { profiler->cpu_profiler = nullptr; } + profiler->measurements_ticker.Cleanup(); delete profiler; }