@@ -124,6 +124,11 @@ static int unpack_instrumentation_scope_attributes(mpack_reader_t *reader, size_
124124 return CTR_DECODE_MSGPACK_VARIANT_DECODE_ERROR ;
125125 }
126126
127+ if (context -> scope_span -> instrumentation_scope -> attr != NULL ) {
128+ ctr_attributes_destroy (context -> scope_span -> instrumentation_scope -> attr );
129+ context -> scope_span -> instrumentation_scope -> attr = NULL ;
130+ }
131+
127132 context -> scope_span -> instrumentation_scope -> attr = attributes ;
128133 }
129134
@@ -132,6 +137,7 @@ static int unpack_instrumentation_scope_attributes(mpack_reader_t *reader, size_
132137
133138static int unpack_scope_span_instrumentation_scope (mpack_reader_t * reader , size_t index , void * ctx )
134139{
140+ int result ;
135141 struct ctrace_instrumentation_scope * instrumentation_scope ;
136142 struct ctr_msgpack_decode_context * context = ctx ;
137143 struct ctr_mpack_map_entry_callback_t callbacks [] = \
@@ -151,7 +157,12 @@ static int unpack_scope_span_instrumentation_scope(mpack_reader_t *reader, size_
151157
152158 ctr_scope_span_set_instrumentation_scope (context -> scope_span , instrumentation_scope );
153159
154- return ctr_mpack_unpack_map (reader , callbacks , ctx );
160+ result = ctr_mpack_unpack_map (reader , callbacks , ctx );
161+ if (result != CTR_DECODE_MSGPACK_SUCCESS ) {
162+ ctr_instrumentation_scope_destroy (context -> scope_span -> instrumentation_scope );
163+ context -> scope_span -> instrumentation_scope = NULL ;
164+ }
165+ return result ;
155166}
156167
157168/* Event callbacks */
@@ -541,6 +552,7 @@ static int unpack_span_status(mpack_reader_t *reader, size_t index, void *ctx)
541552
542553static int unpack_span (mpack_reader_t * reader , size_t index , void * ctx )
543554{
555+ int result ;
544556 struct ctr_msgpack_decode_context * context = ctx ;
545557 struct ctr_mpack_map_entry_callback_t callbacks [] = \
546558 {
@@ -565,8 +577,14 @@ static int unpack_span(mpack_reader_t *reader, size_t index, void *ctx)
565577 if (context -> span == NULL ) {
566578 return CTR_DECODE_MSGPACK_ALLOCATION_ERROR ;
567579 }
580+ result = ctr_mpack_unpack_map (reader , callbacks , ctx );
568581
569- return ctr_mpack_unpack_map (reader , callbacks , ctx );
582+ if (result != CTR_DECODE_MSGPACK_SUCCESS ) {
583+ ctr_span_destroy (context -> span );
584+ context -> span = NULL ;
585+ }
586+
587+ return result ;
570588}
571589
572590/* Scope span callbacks */
@@ -591,6 +609,7 @@ static int unpack_scope_span_schema_url(mpack_reader_t *reader, size_t index, vo
591609
592610static int unpack_scope_span (mpack_reader_t * reader , size_t index , void * ctx )
593611{
612+ int result ;
594613 struct ctr_msgpack_decode_context * context = ctx ;
595614 struct ctr_mpack_map_entry_callback_t callbacks [] = \
596615 {
@@ -606,7 +625,12 @@ static int unpack_scope_span(mpack_reader_t *reader, size_t index, void *ctx)
606625 return CTR_DECODE_MSGPACK_ALLOCATION_ERROR ;
607626 }
608627
609- return ctr_mpack_unpack_map (reader , callbacks , ctx );
628+ result = ctr_mpack_unpack_map (reader , callbacks , ctx );
629+ if (result != CTR_DECODE_MSGPACK_SUCCESS ) {
630+ ctr_scope_span_destroy (context -> scope_span );
631+ context -> scope_span = NULL ;
632+ }
633+ return result ;
610634}
611635
612636/* Resource span callbacks */
0 commit comments