Skip to content

Commit 17343f3

Browse files
committed
Ensure profiler is stopped before disposing of it
1 parent ab2ddb2 commit 17343f3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

bindings/profilers/wall.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,6 @@ WallProfiler::WallProfiler(std::chrono::microseconds samplingPeriod,
582582
}
583583
}
584584

585-
WallProfiler::~WallProfiler() {
586-
Dispose(nullptr, true);
587-
}
588-
589585
void WallProfiler::Dispose(Isolate* isolate, bool removeFromMap) {
590586
if (cpuProfiler_ != nullptr) {
591587
cpuProfiler_->Dispose();
@@ -595,7 +591,7 @@ void WallProfiler::Dispose(Isolate* isolate, bool removeFromMap) {
595591
g_profilers.RemoveProfiler(isolate, this);
596592
}
597593

598-
if (isolate != nullptr && collectAsyncId_) {
594+
if (collectAsyncId_) {
599595
isolate->RemoveGCPrologueCallback(&GCPrologueCallback, this);
600596
isolate->RemoveGCEpilogueCallback(&GCEpilogueCallback, this);
601597
}
@@ -1057,8 +1053,11 @@ NAN_METHOD(WallProfiler::V8ProfilerStuckEventLoopDetected) {
10571053
}
10581054

10591055
NAN_METHOD(WallProfiler::Dispose) {
1060-
// Profiler should already be stopped when this is called.
10611056
auto profiler = Nan::ObjectWrap::Unwrap<WallProfiler>(info.This());
1057+
// Profiler must already be stopped when this is called.
1058+
if (profiler->started_) {
1059+
return Nan::ThrowTypeError("Profiler is still running, stop it first.");
1060+
}
10621061
delete profiler;
10631062
}
10641063

bindings/profilers/wall.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class WallProfiler : public Nan::ObjectWrap {
9292
using ContextBuffer = std::vector<SampleContext>;
9393
ContextBuffer contexts_;
9494

95-
~WallProfiler();
95+
~WallProfiler() = default;
9696
void Dispose(v8::Isolate* isolate, bool removeFromMap);
9797

9898
// A new CPU profiler object will be created each time profiling is started

0 commit comments

Comments
 (0)