From 632966aad55d39c94fd8a57b113f3c49a2d4c89c Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Wed, 11 Oct 2023 16:23:39 -0300 Subject: [PATCH] in_calyptia_fleet: generate_base_fleet_directory now allocates the flb_sds_t for the caller. Signed-off-by: Phillip Whelan --- plugins/in_calyptia_fleet/in_calyptia_fleet.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.c b/plugins/in_calyptia_fleet/in_calyptia_fleet.c index 92ed34285c6..efa540eb0f7 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.c +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.c @@ -192,8 +192,13 @@ struct reload_ctx { flb_sds_t cfg_path; }; -static flb_sds_t generate_fleet_directory(struct flb_in_calyptia_fleet_config *ctx, flb_sds_t *fleet_dir) +static flb_sds_t generate_base_fleet_directory(struct flb_in_calyptia_fleet_config *ctx, flb_sds_t *fleet_dir) { + *fleet_dir = flb_sds_create_size(4096); + if (*fleet_dir == NULL) { + return NULL; + } + if (ctx->fleet_name != NULL) { return flb_sds_printf(fleet_dir, "%s" PATH_SEPARATOR "%s" PATH_SEPARATOR "%s", ctx->config_dir, ctx->machine_id, ctx->fleet_name); @@ -1082,12 +1087,7 @@ static int calyptia_config_delete_old(struct flb_in_calyptia_fleet_config *ctx) flb_sds_t glob_ini; int idx; - glob_ini = flb_sds_create_size(128); - if (glob_ini == NULL) { - return -1; - } - - if (generate_fleet_directory(ctx, &glob_ini) == NULL) { + if (generate_base_fleet_directory(ctx, &glob_ini) == NULL) { flb_sds_destroy(glob_ini); return -1; } @@ -1111,6 +1111,7 @@ static int calyptia_config_delete_old(struct flb_in_calyptia_fleet_config *ctx) unlink(inis->entries[idx]->data.as_string); } + flb_sds_destroy(glob_ini); return 0; } @@ -1339,9 +1340,7 @@ static int create_fleet_directory(struct flb_in_calyptia_fleet_config *ctx) } } - myfleetdir = flb_sds_create_size(256); - - if (generate_fleet_directory(ctx, &myfleetdir) == NULL) { + if (generate_base_fleet_directory(ctx, &myfleetdir) == NULL) { flb_sds_destroy(myfleetdir); return -1; }