Skip to content

Commit

Permalink
in_calyptia_fleet: fix warnings in error handling code for get_calypt…
Browse files Browse the repository at this point in the history
…ia_file.

Signed-off-by: Phillip Whelan <[email protected]>
  • Loading branch information
pwhelan authored and edsiper committed Dec 18, 2023
1 parent ca7bb0d commit 220e1ba
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions plugins/in_calyptia_fleet/in_calyptia_fleet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 220e1ba

Please sign in to comment.