Skip to content

Commit

Permalink
src: nullcheck on trace controller
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gireeshpunathil committed Feb 8, 2019
1 parent d6a32cf commit 9605060
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ Environment::Environment(IsolateData* isolate_data,
if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) {
trace_state_observer_ = std::make_unique<TrackingTraceStateObserver>(this);
TracingController* tracing_controller = writer->GetTracingController();
if (tracing_controller != nullptr)
tracing_controller->AddTraceStateObserver(trace_state_observer_.get());
tracing_controller->AddTraceStateObserver(trace_state_observer_.get());
}

destroy_async_id_list_.reserve(512);
Expand Down Expand Up @@ -272,8 +271,7 @@ Environment::~Environment() {
tracing::AgentWriterHandle* writer = GetTracingAgentWriter();
CHECK_NOT_NULL(writer);
TracingController* tracing_controller = writer->GetTracingController();
if (tracing_controller != nullptr)
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
}

delete[] heap_statistics_buffer_;
Expand Down
1 change: 1 addition & 0 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ double NodePlatform::CurrentClockTimeMillis() {
}

TracingController* NodePlatform::GetTracingController() {
CHECK_NOT_NULL(tracing_controller_);
return tracing_controller_;
}

Expand Down
4 changes: 3 additions & 1 deletion src/tracing/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class Agent {
~Agent();

TracingController* GetTracingController() {
return tracing_controller_.get();
TracingController* controller = tracing_controller_.get();
CHECK_NOT_NULL(controller);
return controller;
}

enum UseDefaultCategoryMode {
Expand Down

0 comments on commit 9605060

Please sign in to comment.