Skip to content

Commit

Permalink
out_opentelemetry: added missing result checks and fixed leaks
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Alminana <[email protected]>
  • Loading branch information
leonardo-albertovich committed Nov 18, 2024
1 parent 600b5a9 commit 348b6a1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion plugins/out_opentelemetry/opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ int opentelemetry_post(struct opentelemetry_context *ctx,
const char *compression_algorithm;
uint32_t wire_message_length;
size_t grpc_body_length;
cfl_sds_t sds_result;
cfl_sds_t grpc_body;
struct flb_http_response *response;
struct flb_http_request *request;
Expand Down Expand Up @@ -261,19 +262,41 @@ int opentelemetry_post(struct opentelemetry_context *ctx,
grpc_body = cfl_sds_create_size(body_len + 5);

if (grpc_body == NULL) {
flb_http_client_request_destroy(request, FLB_TRUE);

return FLB_RETRY;
}

wire_message_length = (uint32_t) body_len;

cfl_sds_cat(grpc_body, "\x00----", 5);

if (sds_result == NULL) {
flb_http_client_request_destroy(request, FLB_TRUE);

cfl_sds_destroy(grpc_body);

return FLB_RETRY;
}

grpc_body = sds_result;

((uint8_t *) grpc_body)[1] = (wire_message_length & 0xFF000000) >> 24;
((uint8_t *) grpc_body)[2] = (wire_message_length & 0x00FF0000) >> 16;
((uint8_t *) grpc_body)[3] = (wire_message_length & 0x0000FF00) >> 8;
((uint8_t *) grpc_body)[4] = (wire_message_length & 0x000000FF) >> 0;

cfl_sds_cat(grpc_body, body, body_len);
sds_result = cfl_sds_cat(grpc_body, body, body_len);

if (sds_result == NULL) {
flb_http_client_request_destroy(request, FLB_TRUE);

cfl_sds_destroy(grpc_body);

return FLB_RETRY;
}

grpc_body = sds_result;

grpc_body_length = cfl_sds_len(grpc_body);

Expand Down

0 comments on commit 348b6a1

Please sign in to comment.