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

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>
  • Loading branch information
gireeshpunathil authored and addaleax committed Feb 8, 2019
1 parent 1b8d2ca commit e0af205
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 @@ -201,8 +201,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 @@ -265,8 +264,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 e0af205

Please sign in to comment.