Skip to content

Commit 98a0770

Browse files
fhinkelMylesBorins
authored andcommitted
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: #17012 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
1 parent 2eec944 commit 98a0770

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/node.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ node::DebugOptions debug_options;
263263
static struct {
264264
#if NODE_USE_V8_PLATFORM
265265
void Initialize(int thread_pool_size) {
266-
tracing_agent_ =
267-
trace_enabled ? new tracing::Agent() : nullptr;
266+
tracing_agent_.reset(
267+
trace_enabled ? new tracing::Agent() : nullptr);
268268
platform_ = new NodePlatform(thread_pool_size,
269269
trace_enabled ? tracing_agent_->GetTracingController() : nullptr);
270270
V8::InitializePlatform(platform_);
@@ -276,8 +276,7 @@ static struct {
276276
platform_->Shutdown();
277277
delete platform_;
278278
platform_ = nullptr;
279-
delete tracing_agent_;
280-
tracing_agent_ = nullptr;
279+
tracing_agent_.reset(nullptr);
281280
}
282281

283282
void DrainVMTasks(Isolate* isolate) {
@@ -314,7 +313,7 @@ static struct {
314313
return platform_;
315314
}
316315

317-
tracing::Agent* tracing_agent_;
316+
std::unique_ptr<tracing::Agent> tracing_agent_;
318317
NodePlatform* platform_;
319318
#else // !NODE_USE_V8_PLATFORM
320319
void Initialize(int thread_pool_size) {}

0 commit comments

Comments
 (0)