Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
src: use unique pointer for tracing_agent
Use std::unique_ptr instead of raw pointers for the
tracing_agent_ in node.cc. This makes ownership clearer and we
don't risk a memory leak.
  • Loading branch information
fhinkel committed Nov 14, 2017
commit 0f96d040ef29533b641a34e13cb0b7fed79f66df
9 changes: 4 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ node::DebugOptions debug_options;
static struct {
#if NODE_USE_V8_PLATFORM
void Initialize(int thread_pool_size) {
tracing_agent_ =
trace_enabled ? new tracing::Agent() : nullptr;
tracing_agent_.reset(
trace_enabled ? new tracing::Agent() : nullptr);
platform_ = new NodePlatform(thread_pool_size,
trace_enabled ? tracing_agent_->GetTracingController() : nullptr);
V8::InitializePlatform(platform_);
Expand All @@ -276,8 +276,7 @@ static struct {
platform_->Shutdown();
delete platform_;
platform_ = nullptr;
delete tracing_agent_;
tracing_agent_ = nullptr;
tracing_agent_.reset(nullptr);
}

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

tracing::Agent* tracing_agent_;
std::unique_ptr<tracing::Agent> tracing_agent_;
NodePlatform* platform_;
#else // !NODE_USE_V8_PLATFORM
void Initialize(int thread_pool_size) {}
Expand Down