diff --git a/src/ctr_encode_opentelemetry.c b/src/ctr_encode_opentelemetry.c index 8f0c81e..a7c12e3 100644 --- a/src/ctr_encode_opentelemetry.c +++ b/src/ctr_encode_opentelemetry.c @@ -20,6 +20,9 @@ #include #include +static void destroy_scope_spans(Opentelemetry__Proto__Trace__V1__ScopeSpans **scope_spans, + size_t count); + static inline Opentelemetry__Proto__Common__V1__AnyValue *ctr_variant_to_otlp_any_value(struct cfl_variant *value); static inline Opentelemetry__Proto__Common__V1__KeyValue *ctr_variant_kvpair_to_otlp_kvpair(struct cfl_kvpair *input_pair); static inline Opentelemetry__Proto__Common__V1__AnyValue *ctr_variant_kvlist_to_otlp_any_value(struct cfl_variant *value); @@ -976,6 +979,12 @@ static Opentelemetry__Proto__Trace__V1__ScopeSpans **set_scope_spans(struct ctra otel_scope_span = initialize_scope_span(); if (!otel_scope_span) { + if (scope_span_index > 0) { + destroy_scope_spans(scope_spans, scope_span_index - 1); + } + + free(scope_spans); + return NULL; }