Destruct CensusContext to avoid leaking memory.

Otherwise, the placement-new leaks context -> span_ -> impl_ which is
a std::shared_ptr.
pull/17554/head
easy 6 years ago
parent 8114c05a2f
commit 8279777167
  1. 6
      src/cpp/ext/filters/census/context.cc

@ -28,6 +28,9 @@ using ::opencensus::trace::SpanContext;
void GenerateServerContext(absl::string_view tracing, absl::string_view stats,
absl::string_view primary_role,
absl::string_view method, CensusContext* context) {
// Destruct the current CensusContext to free the Span memory before
// overwriting it below.
context->~CensusContext();
GrpcTraceContext trace_ctxt;
if (TraceContextEncoding::Decode(tracing, &trace_ctxt) !=
TraceContextEncoding::kEncodeDecodeFailure) {
@ -42,6 +45,9 @@ void GenerateServerContext(absl::string_view tracing, absl::string_view stats,
void GenerateClientContext(absl::string_view method, CensusContext* ctxt,
CensusContext* parent_ctxt) {
// Destruct the current CensusContext to free the Span memory before
// overwriting it below.
ctxt->~CensusContext();
if (parent_ctxt != nullptr) {
SpanContext span_ctxt = parent_ctxt->Context();
Span span = parent_ctxt->Span();

Loading…
Cancel
Save