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: nodejs#25814

PR-URL: nodejs#25943
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Masashi Hirano <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
gireeshpunathil authored and addaleax committed Feb 8, 2019
1 parent 3a4521a commit c70e853
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 c70e853

Please sign in to comment.