Skip to content

Commit

Permalink
src: use unique pointer for tracing_agent
Browse files Browse the repository at this point in the history
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.

PR-URL: #17012
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
  • Loading branch information
fhinkel authored and MylesBorins committed Dec 11, 2017
1 parent 2eec944 commit 98a0770
Showing 1 changed file with 4 additions and 5 deletions.
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

0 comments on commit 98a0770

Please sign in to comment.