Skip to content
Permalink
Browse files

src: do not leak NodeTraceStateObserver

This would otherwise be reported as a memory leak by automated tools.

PR-URL: #25180
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information...
addaleax authored and targos committed Dec 22, 2018
1 parent 5b4fab1 commit 7365b009298c7452e52cbd701ab2ae579afba27c
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/node.cc
@@ -211,7 +211,6 @@ class NodeTraceStateObserver :

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

void OnTraceDisabled() override {
@@ -233,8 +232,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);
@@ -248,6 +249,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) {
@@ -300,6 +302,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_;

0 comments on commit 7365b00

Please sign in to comment.
You can’t perform that action at this time.