Skip to content

Commit

Permalink
src: do not leak NodeTraceStateObserver
Browse files Browse the repository at this point in the history
This would otherwise be reported as a memory leak by automated tools.

PR-URL: #25180
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
addaleax authored and MylesBorins committed May 16, 2019
1 parent 4fcfa5a commit 5d5ac23
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class NodeTraceStateObserver :

// This only runs the first time tracing is enabled
controller_->RemoveTraceStateObserver(this);
delete this;
}

void OnTraceDisabled() override {
Expand All @@ -280,8 +279,10 @@ static struct {
void Initialize(int thread_pool_size) {
tracing_agent_.reset(new tracing::Agent());
node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get());
auto controller = tracing_agent_->GetTracingController();
controller->AddTraceStateObserver(new NodeTraceStateObserver(controller));
node::tracing::TracingController* controller =
tracing_agent_->GetTracingController();
trace_state_observer_.reset(new NodeTraceStateObserver(controller));
controller->AddTraceStateObserver(trace_state_observer_.get());
StartTracingAgent();
// Tracing must be initialized before platform threads are created.
platform_ = new NodePlatform(thread_pool_size, controller);
Expand All @@ -295,6 +296,7 @@ static struct {
// Destroy tracing after the platform (and platform threads) have been
// stopped.
tracing_agent_.reset(nullptr);
trace_state_observer_.reset(nullptr);
}

void DrainVMTasks(Isolate* isolate) {
Expand Down Expand Up @@ -345,6 +347,7 @@ static struct {
return platform_;
}

std::unique_ptr<NodeTraceStateObserver> trace_state_observer_;
std::unique_ptr<tracing::Agent> tracing_agent_;
tracing::AgentWriterHandle tracing_file_writer_;
NodePlatform* platform_;
Expand Down

0 comments on commit 5d5ac23

Please sign in to comment.