From 220e1ba4be81912150dc53795e7bd88d72476433 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Mon, 11 Dec 2023 20:49:24 -0300 Subject: [PATCH] in_calyptia_fleet: fix warnings in error handling code for get_calyptia_file. Signed-off-by: Phillip Whelan --- plugins/in_calyptia_fleet/in_calyptia_fleet.c | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.c b/plugins/in_calyptia_fleet/in_calyptia_fleet.c index d3a16d4f2d8..269d7711e3f 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.c +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.c @@ -1012,33 +1012,34 @@ static int get_calyptia_file(struct flb_in_calyptia_fleet_config *ctx, fname = flb_sds_create_len(dst, strlen(dst)); } + if (fname == NULL) { + goto file_name_error; + } + if (access(fname, F_OK) == 0) { ret = 0; - goto file_exists; + goto file_error; } - if (fname == NULL) { - goto client_error; - } fp = fopen(fname, "w+"); if (fp == NULL) { - goto client_error; + goto file_error; } if (hdr != NULL) { len = fwrite(hdr, strlen(hdr), 1, fp); if (len < 1) { flb_plg_error(ctx->ins, "truncated write: %s", dst); - goto file_error; + goto file_write_error; } } len = fwrite(client->resp.payload, client->resp.payload_size, 1, fp); if (len < 1) { flb_plg_error(ctx->ins, "truncated write: %s", dst); - goto file_error; + goto file_write_error; } if (time_last_modified) { @@ -1047,11 +1048,12 @@ static int get_calyptia_file(struct flb_in_calyptia_fleet_config *ctx, ret = 1; -file_error: +file_write_error: fclose(fp); -client_error: +file_name_error: +file_error: flb_sds_destroy(fname); -file_exists: +client_error: flb_http_client_destroy(client); return ret; }