From 0f96d040ef29533b641a34e13cb0b7fed79f66df Mon Sep 17 00:00:00 2001 From: Franziska Hinkelmann Date: Sun, 12 Nov 2017 22:16:10 +0100 Subject: [PATCH] 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. --- src/node.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/node.cc b/src/node.cc index 05120fbde1fb1a..fd21687c0c59ac 100644 --- a/src/node.cc +++ b/src/node.cc @@ -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_); @@ -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) { @@ -314,7 +313,7 @@ static struct { return platform_; } - tracing::Agent* tracing_agent_; + std::unique_ptr tracing_agent_; NodePlatform* platform_; #else // !NODE_USE_V8_PLATFORM void Initialize(int thread_pool_size) {}