From e0af205c982ccb9c407eaec46108a080f1ce3bb2 Mon Sep 17 00:00:00 2001 From: Gireesh Punathil Date: Tue, 5 Feb 2019 00:00:05 -0500 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/25814 PR-URL: https://github.com/nodejs/node/pull/25943 Reviewed-By: James M Snell Reviewed-By: Masashi Hirano Reviewed-By: Richard Lau Reviewed-By: Anna Henningsen --- src/env.cc | 6 ++---- src/node_platform.cc | 1 + src/tracing/agent.h | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/env.cc b/src/env.cc index 78ed42f89af9fc..bdec7129e0bca6 100644 --- a/src/env.cc +++ b/src/env.cc @@ -201,8 +201,7 @@ Environment::Environment(IsolateData* isolate_data, if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) { trace_state_observer_ = std::make_unique(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); @@ -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_; diff --git a/src/node_platform.cc b/src/node_platform.cc index 797d4d9cbb0dac..f591a074a530da 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -459,6 +459,7 @@ double NodePlatform::CurrentClockTimeMillis() { } TracingController* NodePlatform::GetTracingController() { + CHECK_NOT_NULL(tracing_controller_); return tracing_controller_; } diff --git a/src/tracing/agent.h b/src/tracing/agent.h index d7d67ce2de6372..2e95e38582f7eb 100644 --- a/src/tracing/agent.h +++ b/src/tracing/agent.h @@ -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 {