diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.c b/plugins/in_calyptia_fleet/in_calyptia_fleet.c index 1039a68d20c..b2f48ea6e1a 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.c +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.c @@ -67,7 +67,11 @@ struct flb_in_calyptia_fleet_config { long config_timestamp; flb_sds_t api_key; + flb_sds_t fleet_id; + /* flag used to mark fleet_id for release when found automatically. */ + int fleet_id_found; + flb_sds_t fleet_name; flb_sds_t machine_id; flb_sds_t config_dir; @@ -375,6 +379,7 @@ static void *do_reload(void *data) reload->flb->config->enable_hot_reload = FLB_TRUE; reload->flb->config->conf_path_file = reload->cfg_path; + flb_free(reload); sleep(5); #ifndef FLB_SYSTEM_WINDOWS kill(getpid(), SIGHUP); @@ -386,21 +391,14 @@ static void *do_reload(void *data) static int test_config_is_valid(flb_sds_t cfgpath) { - struct flb_config *config; struct flb_cf *conf; int ret = FLB_FALSE; - config = flb_config_init(); - - if (config == NULL) { - goto config_init_error; - } - conf = flb_cf_create(); if (conf == NULL) { - goto cf_create_error; + goto config_init_error; } conf = flb_cf_create_from_file(conf, cfgpath); @@ -409,22 +407,10 @@ static int test_config_is_valid(flb_sds_t cfgpath) goto cf_create_from_file_error; } - if (flb_config_load_config_format(config, conf)) { - goto cf_load_config_format_error; - } - - if (flb_reload_property_check_all(config)) { - goto cf_property_check_error; - } - ret = FLB_TRUE; -cf_property_check_error: -cf_load_config_format_error: cf_create_from_file_error: flb_cf_destroy(conf); -cf_create_error: - flb_config_exit(config); config_init_error: return ret; } @@ -447,6 +433,7 @@ static int execute_reload(struct flb_in_calyptia_fleet_config *ctx, flb_sds_t cf flb_input_collector_resume(ctx->collect_fd, ctx->ins); } + flb_sds_destroy(cfgpath); return FLB_FALSE; } @@ -463,6 +450,7 @@ static int execute_reload(struct flb_in_calyptia_fleet_config *ctx, flb_sds_t cf flb_input_collector_resume(ctx->collect_fd, ctx->ins); } + flb_sds_destroy(cfgpath); return FLB_FALSE; } @@ -609,6 +597,7 @@ static ssize_t parse_fleet_search_json(struct flb_in_calyptia_fleet_config *ctx, return -1; } + ctx->fleet_id_found = 1; ctx->fleet_id = flb_sds_create_len(cur->val.via.str.ptr, cur->val.via.str.size); break; @@ -697,27 +686,34 @@ static int get_calyptia_fleet_id_by_name(struct flb_in_calyptia_fleet_config *ct if (ret != 0) { flb_plg_error(ctx->ins, "http do error"); + flb_http_client_destroy(client); return -1; } if (client->resp.status != 200) { flb_plg_error(ctx->ins, "search http status code error: %d", client->resp.status); + flb_http_client_destroy(client); return -1; } if (client->resp.payload_size <= 0) { flb_plg_error(ctx->ins, "empty response"); + flb_http_client_destroy(client); return -1; } if (parse_fleet_search_json(ctx, client->resp.payload, client->resp.payload_size) == -1) { flb_plg_error(ctx->ins, "unable to find fleet: %s", ctx->fleet_name); + flb_http_client_destroy(client); return -1; } if (ctx->fleet_id == NULL) { + flb_http_client_destroy(client); return -1; } + + flb_http_client_destroy(client); return 0; } @@ -855,6 +851,7 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, if (cfgfp == NULL) { flb_plg_error(ctx->ins, "unable to open configuration file: %s", cfgname); + flb_sds_destroy(cfgname); goto payload_error; } @@ -904,12 +901,14 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, } if (hdr == NULL) { fclose(cfgfp); + flb_sds_destroy(cfgname); goto header_error; } if (ctx->machine_id) { hdr = flb_sds_printf(&header, " machine_id %s\n", ctx->machine_id); if (hdr == NULL) { fclose(cfgfp); + flb_sds_destroy(cfgname); goto header_error; } } @@ -938,13 +937,13 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, flb_errno(); #endif } + + flb_sds_destroy(cfgnewname); } if (ctx->config_timestamp < time_last_modified) { flb_plg_debug(ctx->ins, "new configuration is newer than current: %ld < %ld", ctx->config_timestamp, time_last_modified); - flb_sds_destroy(data); - data = NULL; if (execute_reload(ctx, cfgname) == FLB_FALSE) { cfgoldname = old_fleet_config_filename(ctx); @@ -952,11 +951,12 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, rename(cfgoldname, cfgcurname); flb_sds_destroy(cfgcurname); flb_sds_destroy(cfgoldname); + flb_sds_destroy(cfgname); goto reload_error; } - else { - FLB_INPUT_RETURN(0); - } + } + else { + flb_sds_destroy(cfgname); } ret = 0; @@ -972,6 +972,7 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, } http_error: + flb_plg_debug(ctx->ins, "freeing http client in fleet collect"); flb_http_client_destroy(client); client_error: flb_upstream_conn_release(u_conn); @@ -1242,6 +1243,14 @@ static int in_calyptia_fleet_exit(void *data, struct flb_config *config) (void) *config; struct flb_in_calyptia_fleet_config *ctx = (struct flb_in_calyptia_fleet_config *)data; + if (ctx->fleet_url) { + flb_sds_destroy(ctx->fleet_url); + } + + if (ctx->fleet_id && ctx->fleet_id_found) { + flb_sds_destroy(ctx->fleet_id); + } + flb_input_collector_delete(ctx->collect_fd, ctx->ins); flb_upstream_destroy(ctx->u); flb_free(ctx);