3333#include <cmetrics/cmt_encode_influx.h>
3434
3535flb_sds_t custom_calyptia_pipeline_config_get (struct flb_config * ctx );
36+ static void calyptia_ctx_destroy (struct flb_calyptia * ctx );
3637
3738static int get_io_flags (struct flb_output_instance * ins )
3839{
@@ -733,35 +734,35 @@ static struct flb_calyptia *config_init(struct flb_output_instance *ins,
733734 /* Load the config map */
734735 ret = flb_output_config_map_set (ins , (void * ) ctx );
735736 if (ret == -1 ) {
736- flb_free (ctx );
737+ calyptia_ctx_destroy (ctx );
737738 return NULL ;
738739 }
739740
740741 ctx -> metrics_endpoint = flb_sds_create_size (256 );
741742 if (!ctx -> metrics_endpoint ) {
742- flb_free (ctx );
743+ calyptia_ctx_destroy (ctx );
743744 return NULL ;
744745 }
745746
746747#ifdef FLB_HAVE_CHUNK_TRACE
747748 ctx -> trace_endpoint = flb_sds_create_size (256 );
748749 if (!ctx -> trace_endpoint ) {
749- flb_sds_destroy (ctx -> metrics_endpoint );
750- flb_free (ctx );
750+ calyptia_ctx_destroy (ctx );
751751 return NULL ;
752752 }
753753#endif
754754
755755 /* api_key */
756756 if (!ctx -> api_key ) {
757757 flb_plg_error (ctx -> ins , "configuration 'api_key' is missing" );
758- flb_free (ctx );
758+ calyptia_ctx_destroy (ctx );
759759 return NULL ;
760760 }
761761
762762 /* parse 'add_label' */
763763 ret = config_add_labels (ins , ctx );
764764 if (ret == -1 ) {
765+ calyptia_ctx_destroy (ctx );
765766 return NULL ;
766767 }
767768
@@ -775,13 +776,17 @@ static struct flb_calyptia *config_init(struct flb_output_instance *ins,
775776 if (ctx -> store_path ) {
776777 ret = store_init (ctx );
777778 if (ret == -1 ) {
779+ flb_output_set_context (ins , NULL );
780+ calyptia_ctx_destroy (ctx );
778781 return NULL ;
779782 }
780783 }
781784
782785 /* the machine-id is provided by custom calyptia, which invokes this plugin. */
783786 if (!ctx -> machine_id ) {
784787 flb_plg_error (ctx -> ins , "machine_id has not been set" );
788+ flb_output_set_context (ins , NULL );
789+ calyptia_ctx_destroy (ctx );
785790 return NULL ;
786791 }
787792
@@ -793,6 +798,8 @@ static struct flb_calyptia *config_init(struct flb_output_instance *ins,
793798 ctx -> cloud_host , ctx -> cloud_port ,
794799 flags , ctx -> ins -> tls );
795800 if (!ctx -> u ) {
801+ flb_output_set_context (ins , NULL );
802+ calyptia_ctx_destroy (ctx );
796803 return NULL ;
797804 }
798805
@@ -878,12 +885,10 @@ static void debug_payload(struct flb_calyptia *ctx, void *data, size_t bytes)
878885 cmt_destroy (cmt );
879886}
880887
881- static int cb_calyptia_exit ( void * data , struct flb_config * config )
888+ static void calyptia_ctx_destroy ( struct flb_calyptia * ctx )
882889{
883- struct flb_calyptia * ctx = data ;
884-
885890 if (!ctx ) {
886- return 0 ;
891+ return ;
887892 }
888893
889894 if (ctx -> u ) {
@@ -910,15 +915,20 @@ static int cb_calyptia_exit(void *data, struct flb_config *config)
910915 if (ctx -> trace_endpoint ) {
911916 flb_sds_destroy (ctx -> trace_endpoint );
912917 }
913- #endif /* FLB_HAVE_CHUNK_TRACE */
918+ #endif
914919
915920 if (ctx -> fs ) {
916921 flb_fstore_destroy (ctx -> fs );
917922 }
918923
919924 flb_kv_release (& ctx -> kv_labels );
920925 flb_free (ctx );
926+ }
921927
928+ static int cb_calyptia_exit (void * data , struct flb_config * config )
929+ {
930+ (void ) config ;
931+ calyptia_ctx_destroy ((struct flb_calyptia * ) data );
922932 return 0 ;
923933}
924934
0 commit comments