@@ -76,7 +76,8 @@ class MeasurementsTicker {
7676 MeasurementsTicker (uv_loop_t *loop)
7777 : period_ms(100 ), isolate(v8::Isolate::GetCurrent()) {
7878 uv_timer_init (loop, &timer);
79- timer.data = this ;
79+ uv_handle_set_data (&timer, this );
80+ uv_unref (reinterpret_cast <uv_handle_t *>(&timer));
8081 }
8182
8283 static void ticker (uv_timer_t *);
@@ -196,6 +197,10 @@ void MeasurementsTicker::cpu_callback() {
196197};
197198
198199void MeasurementsTicker::ticker (uv_timer_t *handle) {
200+ if (handle == nullptr ) {
201+ return ;
202+ }
203+
199204 MeasurementsTicker *self = static_cast <MeasurementsTicker *>(handle->data );
200205 self->heap_callback ();
201206 self->cpu_callback ();
@@ -231,6 +236,19 @@ class Profiler {
231236 : measurements_ticker(uv_default_loop()),
232237 cpu_profiler(
233238 v8::CpuProfiler::New (isolate, kNamingMode , GetLoggingMode())) {}
239+
240+ ~Profiler () {
241+ for (auto &profile : active_profiles) {
242+ CleanupSentryProfile (this , profile.second , profile.first );
243+ }
244+
245+ active_profiles.clear ();
246+
247+ if (cpu_profiler) {
248+ cpu_profiler->Dispose ();
249+ cpu_profiler = nullptr ;
250+ }
251+ }
234252};
235253
236254class SentryProfile {
@@ -1041,16 +1059,6 @@ void FreeAddonData(napi_env env, void *data, void *hint) {
10411059 return ;
10421060 }
10431061
1044- if (!profiler->active_profiles .empty ()) {
1045- for (auto &profile : profiler->active_profiles ) {
1046- CleanupSentryProfile (profiler, profile.second , profile.first );
1047- }
1048- }
1049-
1050- if (profiler->cpu_profiler != nullptr ) {
1051- profiler->cpu_profiler ->Dispose ();
1052- }
1053-
10541062 delete profiler;
10551063}
10561064
0 commit comments