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: nodejs#17012
Backport-PR-URL: nodejs#18179
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 gibfahn committed Jan 17, 2018
1 parent 5d03e0c commit 8a3da7a
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 @@ -272,8 +272,8 @@ node::DebugOptions debug_options;
static struct {
#if NODE_USE_V8_PLATFORM
void Initialize(int thread_pool_size, uv_loop_t* loop) {
tracing_agent_ =
trace_enabled ? new tracing::Agent() : nullptr;
tracing_agent_.reset(
trace_enabled ? new tracing::Agent() : nullptr);
platform_ = new NodePlatform(thread_pool_size, loop,
trace_enabled ? tracing_agent_->GetTracingController() : nullptr);
V8::InitializePlatform(platform_);
Expand All @@ -285,8 +285,7 @@ static struct {
platform_->Shutdown();
delete platform_;
platform_ = nullptr;
delete tracing_agent_;
tracing_agent_ = nullptr;
tracing_agent_.reset(nullptr);
}

void DrainVMTasks() {
Expand Down Expand Up @@ -315,7 +314,7 @@ static struct {
tracing_agent_->Stop();
}

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

0 comments on commit 8a3da7a

Please sign in to comment.