@@ -76,7 +76,8 @@ class MeasurementsTicker {
76
76
MeasurementsTicker (uv_loop_t *loop)
77
77
: period_ms(100 ), isolate(v8::Isolate::GetCurrent()) {
78
78
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));
80
81
}
81
82
82
83
static void ticker (uv_timer_t *);
@@ -196,6 +197,10 @@ void MeasurementsTicker::cpu_callback() {
196
197
};
197
198
198
199
void MeasurementsTicker::ticker (uv_timer_t *handle) {
200
+ if (handle == nullptr ) {
201
+ return ;
202
+ }
203
+
199
204
MeasurementsTicker *self = static_cast <MeasurementsTicker *>(handle->data );
200
205
self->heap_callback ();
201
206
self->cpu_callback ();
@@ -231,6 +236,19 @@ class Profiler {
231
236
: measurements_ticker(uv_default_loop()),
232
237
cpu_profiler(
233
238
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
+ }
234
252
};
235
253
236
254
class SentryProfile {
@@ -1041,16 +1059,6 @@ void FreeAddonData(napi_env env, void *data, void *hint) {
1041
1059
return ;
1042
1060
}
1043
1061
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
-
1054
1062
delete profiler;
1055
1063
}
1056
1064
0 commit comments