Skip to content

Commit e0af205

Browse files
gireeshpunathiladdaleax
authored andcommitted
src: nullcheck on trace controller
Insert a NULLCHECK prior to return. Ideally we do this in the caller, but the TraceController object is somewhat special as: 1. It is accessed by most threads 2. It's life cycle is managed by Agent::Agent 3. It's getter is invoked through Base Methods (upstream) Refs: #25814 PR-URL: #25943 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 1b8d2ca commit e0af205

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/env.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ Environment::Environment(IsolateData* isolate_data,
201201
if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) {
202202
trace_state_observer_ = std::make_unique<TrackingTraceStateObserver>(this);
203203
TracingController* tracing_controller = writer->GetTracingController();
204-
if (tracing_controller != nullptr)
205-
tracing_controller->AddTraceStateObserver(trace_state_observer_.get());
204+
tracing_controller->AddTraceStateObserver(trace_state_observer_.get());
206205
}
207206

208207
destroy_async_id_list_.reserve(512);
@@ -265,8 +264,7 @@ Environment::~Environment() {
265264
tracing::AgentWriterHandle* writer = GetTracingAgentWriter();
266265
CHECK_NOT_NULL(writer);
267266
TracingController* tracing_controller = writer->GetTracingController();
268-
if (tracing_controller != nullptr)
269-
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
267+
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
270268
}
271269

272270
delete[] heap_statistics_buffer_;

src/node_platform.cc

+1
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ double NodePlatform::CurrentClockTimeMillis() {
459459
}
460460

461461
TracingController* NodePlatform::GetTracingController() {
462+
CHECK_NOT_NULL(tracing_controller_);
462463
return tracing_controller_;
463464
}
464465

src/tracing/agent.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ class Agent {
8181
~Agent();
8282

8383
TracingController* GetTracingController() {
84-
return tracing_controller_.get();
84+
TracingController* controller = tracing_controller_.get();
85+
CHECK_NOT_NULL(controller);
86+
return controller;
8587
}
8688

8789
enum UseDefaultCategoryMode {

0 commit comments

Comments
 (0)