diff --git a/src/ctr_encode_opentelemetry.c b/src/ctr_encode_opentelemetry.c
index 8f0c81e..c1e9c24 100644
--- a/src/ctr_encode_opentelemetry.c
+++ b/src/ctr_encode_opentelemetry.c
@@ -976,6 +976,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;
         }