6363static int fleet_cur_chdir (struct flb_in_calyptia_fleet_config * ctx );
6464static int get_calyptia_files (struct flb_in_calyptia_fleet_config * ctx ,
6565 time_t timestamp );
66+ static void in_calyptia_fleet_destroy (struct flb_in_calyptia_fleet_config * ctx );
6667
6768#ifndef FLB_SYSTEM_WINDOWS
6869
@@ -633,8 +634,6 @@ static int execute_reload(struct flb_in_calyptia_fleet_config *ctx, flb_sds_t cf
633634 flb_plg_error (ctx -> ins , "unable to change to configuration directory" );
634635 }
635636
636- fleet_cur_chdir (ctx );
637-
638637 pthread_attr_init (& ptha );
639638 pthread_attr_setdetachstate (& ptha , PTHREAD_CREATE_DETACHED );
640639 pthread_create (& pth , & ptha , do_reload , reload );
@@ -2222,7 +2221,7 @@ static int in_calyptia_fleet_init(struct flb_input_instance *in,
22222221 /* Load the config map */
22232222 ret = flb_input_config_map_set (in , (void * ) ctx );
22242223 if (ret == -1 ) {
2225- flb_free (ctx );
2224+ in_calyptia_fleet_destroy (ctx );
22262225 flb_plg_error (in , "unable to load configuration" );
22272226 return -1 ;
22282227 }
@@ -2233,15 +2232,15 @@ static int in_calyptia_fleet_init(struct flb_input_instance *in,
22332232
22342233 if (tmpdir == NULL ) {
22352234 flb_plg_error (in , "unable to find temporary directory (%%TEMP%%)." );
2236- flb_free (ctx );
2235+ in_calyptia_fleet_destroy (ctx );
22372236 return -1 ;
22382237 }
22392238
22402239 ctx -> config_dir = flb_sds_create_size (CALYPTIA_MAX_DIR_SIZE );
22412240
22422241 if (ctx -> config_dir == NULL ) {
22432242 flb_plg_error (in , "unable to allocate config-dir." );
2244- flb_free (ctx );
2243+ in_calyptia_fleet_destroy (ctx );
22452244 return -1 ;
22462245 }
22472246 flb_sds_printf (& ctx -> config_dir , "%s" PATH_SEPARATOR "%s" , tmpdir , "calyptia-fleet" );
@@ -2259,7 +2258,7 @@ static int in_calyptia_fleet_init(struct flb_input_instance *in,
22592258
22602259 if (!ctx -> u ) {
22612260 flb_plg_error (ctx -> ins , "could not initialize upstream" );
2262- flb_free (ctx );
2261+ in_calyptia_fleet_destroy (ctx );
22632262 return -1 ;
22642263 }
22652264
@@ -2281,6 +2280,7 @@ static int in_calyptia_fleet_init(struct flb_input_instance *in,
22812280 /* create fleet directory before creating the fleet header. */
22822281 if (create_fleet_directory (ctx ) != 0 ) {
22832282 flb_plg_error (ctx -> ins , "unable to create fleet directories" );
2283+ in_calyptia_fleet_destroy (ctx );
22842284 return -1 ;
22852285 }
22862286
@@ -2309,8 +2309,7 @@ static int in_calyptia_fleet_init(struct flb_input_instance *in,
23092309
23102310 if (ret == -1 ) {
23112311 flb_plg_error (ctx -> ins , "could not initialize collector for fleet input plugin" );
2312- flb_upstream_destroy (ctx -> u );
2313- flb_free (ctx );
2312+ in_calyptia_fleet_destroy (ctx );
23142313 return -1 ;
23152314 }
23162315
@@ -2333,10 +2332,11 @@ static void cb_in_calyptia_fleet_resume(void *data, struct flb_config *config)
23332332 flb_input_collector_resume (ctx -> collect_fd , ctx -> ins );
23342333}
23352334
2336- static int in_calyptia_fleet_exit ( void * data , struct flb_config * config )
2335+ static void in_calyptia_fleet_destroy ( struct flb_in_calyptia_fleet_config * ctx )
23372336{
2338- (void ) * config ;
2339- struct flb_in_calyptia_fleet_config * ctx = (struct flb_in_calyptia_fleet_config * )data ;
2337+ if (!ctx ) {
2338+ return ;
2339+ }
23402340
23412341 if (ctx -> fleet_url ) {
23422342 flb_sds_destroy (ctx -> fleet_url );
@@ -2350,10 +2350,21 @@ static int in_calyptia_fleet_exit(void *data, struct flb_config *config)
23502350 flb_sds_destroy (ctx -> fleet_id );
23512351 }
23522352
2353- flb_input_collector_delete (ctx -> collect_fd , ctx -> ins );
2354- flb_upstream_destroy (ctx -> u );
2353+ if (ctx -> collect_fd >= 0 ) {
2354+ flb_input_collector_delete (ctx -> collect_fd , ctx -> ins );
2355+ }
2356+
2357+ if (ctx -> u ) {
2358+ flb_upstream_destroy (ctx -> u );
2359+ }
2360+
23552361 flb_free (ctx );
2362+ }
23562363
2364+ static int in_calyptia_fleet_exit (void * data , struct flb_config * config )
2365+ {
2366+ (void ) * config ;
2367+ in_calyptia_fleet_destroy ((struct flb_in_calyptia_fleet_config * )data );
23572368 return 0 ;
23582369}
23592370
0 commit comments