@@ -627,6 +627,7 @@ struct flb_output_flush *flb_output_flush_create(struct flb_task *task,
627627 struct cmt * metrics_context ;
628628 struct ctrace * trace_context ;
629629 size_t chunk_offset ;
630+ struct cmt * cmt_out_context = NULL ;
630631
631632 /* Custom output coroutine info */
632633 out_flush = (struct flb_output_flush * ) flb_calloc (1 , sizeof (struct flb_output_flush ));
@@ -715,13 +716,25 @@ struct flb_output_flush *flb_output_flush_create(struct flb_task *task,
715716 flb_sds_len (evc -> tag ),
716717 (char * ) metrics_context ,
717718 0 ,
718- NULL ,
719+ ( void * * ) & cmt_out_context ,
719720 NULL );
720721
721722 if (ret == 0 ) {
722- ret = cmt_encode_msgpack_create (metrics_context ,
723- & serialized_context_buffer ,
724- & serialized_context_size );
723+ if (cmt_out_context != NULL ) {
724+ ret = cmt_encode_msgpack_create (cmt_out_context ,
725+ & serialized_context_buffer ,
726+ & serialized_context_size );
727+
728+ if (cmt_out_context != metrics_context ) {
729+ cmt_destroy (cmt_out_context );
730+ }
731+
732+ }
733+ else {
734+ ret = cmt_encode_msgpack_create (metrics_context ,
735+ & serialized_context_buffer ,
736+ & serialized_context_size );
737+ }
725738
726739 cmt_destroy (metrics_context );
727740
0 commit comments