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. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
9ae81b9cb9
commit
787863ddb4
@ -273,8 +273,8 @@ node::DebugOptions debug_options;
|
|||||||
static struct {
|
static struct {
|
||||||
#if NODE_USE_V8_PLATFORM
|
#if NODE_USE_V8_PLATFORM
|
||||||
void Initialize(int thread_pool_size) {
|
void Initialize(int thread_pool_size) {
|
||||||
tracing_agent_ =
|
tracing_agent_.reset(
|
||||||
trace_enabled ? new tracing::Agent() : nullptr;
|
trace_enabled ? new tracing::Agent() : nullptr);
|
||||||
platform_ = new NodePlatform(thread_pool_size,
|
platform_ = new NodePlatform(thread_pool_size,
|
||||||
trace_enabled ? tracing_agent_->GetTracingController() : nullptr);
|
trace_enabled ? tracing_agent_->GetTracingController() : nullptr);
|
||||||
V8::InitializePlatform(platform_);
|
V8::InitializePlatform(platform_);
|
||||||
@ -286,8 +286,7 @@ static struct {
|
|||||||
platform_->Shutdown();
|
platform_->Shutdown();
|
||||||
delete platform_;
|
delete platform_;
|
||||||
platform_ = nullptr;
|
platform_ = nullptr;
|
||||||
delete tracing_agent_;
|
tracing_agent_.reset(nullptr);
|
||||||
tracing_agent_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrainVMTasks(Isolate* isolate) {
|
void DrainVMTasks(Isolate* isolate) {
|
||||||
@ -324,7 +323,7 @@ static struct {
|
|||||||
return platform_;
|
return platform_;
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing::Agent* tracing_agent_;
|
std::unique_ptr<tracing::Agent> tracing_agent_;
|
||||||
NodePlatform* platform_;
|
NodePlatform* platform_;
|
||||||
#else // !NODE_USE_V8_PLATFORM
|
#else // !NODE_USE_V8_PLATFORM
|
||||||
void Initialize(int thread_pool_size) {}
|
void Initialize(int thread_pool_size) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user