Skip to content

Commit ace2c2f

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. Backport-PR-URL: #18179 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 e71beba commit ace2c2f

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
@@ -272,8 +272,8 @@ node::DebugOptions debug_options;
272272
static struct {
273273
#if NODE_USE_V8_PLATFORM
274274
void Initialize(int thread_pool_size, uv_loop_t* loop) {
275-
tracing_agent_ =
276-
trace_enabled ? new tracing::Agent() : nullptr;
275+
tracing_agent_.reset(
276+
trace_enabled ? new tracing::Agent() : nullptr);
277277
platform_ = new NodePlatform(thread_pool_size, loop,
278278
trace_enabled ? tracing_agent_->GetTracingController() : nullptr);
279279
V8::InitializePlatform(platform_);
@@ -285,8 +285,7 @@ static struct {
285285
platform_->Shutdown();
286286
delete platform_;
287287
platform_ = nullptr;
288-
delete tracing_agent_;
289-
tracing_agent_ = nullptr;
288+
tracing_agent_.reset(nullptr);
290289
}
291290

292291
void DrainVMTasks() {
@@ -315,7 +314,7 @@ static struct {
315314
tracing_agent_->Stop();
316315
}
317316

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

0 commit comments

Comments
 (0)