Skip to content

Commit 889afec

Browse files
Leonardo Alminanaedsiper
authored andcommitted
out_opentelemetry: added missing result checks and fixed leaks
Signed-off-by: Leonardo Alminana <[email protected]>
1 parent ed3cad6 commit 889afec

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

plugins/out_opentelemetry/opentelemetry.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ int opentelemetry_post(struct opentelemetry_context *ctx,
227227
const char *compression_algorithm;
228228
uint32_t wire_message_length;
229229
size_t grpc_body_length;
230+
cfl_sds_t sds_result;
230231
cfl_sds_t grpc_body;
231232
struct flb_http_response *response;
232233
struct flb_http_request *request;
@@ -261,19 +262,41 @@ int opentelemetry_post(struct opentelemetry_context *ctx,
261262
grpc_body = cfl_sds_create_size(body_len + 5);
262263

263264
if (grpc_body == NULL) {
265+
flb_http_client_request_destroy(request, FLB_TRUE);
266+
264267
return FLB_RETRY;
265268
}
266269

267270
wire_message_length = (uint32_t) body_len;
268271

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

274+
if (sds_result == NULL) {
275+
flb_http_client_request_destroy(request, FLB_TRUE);
276+
277+
cfl_sds_destroy(grpc_body);
278+
279+
return FLB_RETRY;
280+
}
281+
282+
grpc_body = sds_result;
283+
271284
((uint8_t *) grpc_body)[1] = (wire_message_length & 0xFF000000) >> 24;
272285
((uint8_t *) grpc_body)[2] = (wire_message_length & 0x00FF0000) >> 16;
273286
((uint8_t *) grpc_body)[3] = (wire_message_length & 0x0000FF00) >> 8;
274287
((uint8_t *) grpc_body)[4] = (wire_message_length & 0x000000FF) >> 0;
275288

276-
cfl_sds_cat(grpc_body, body, body_len);
289+
sds_result = cfl_sds_cat(grpc_body, body, body_len);
290+
291+
if (sds_result == NULL) {
292+
flb_http_client_request_destroy(request, FLB_TRUE);
293+
294+
cfl_sds_destroy(grpc_body);
295+
296+
return FLB_RETRY;
297+
}
298+
299+
grpc_body = sds_result;
277300

278301
grpc_body_length = cfl_sds_len(grpc_body);
279302

0 commit comments

Comments
 (0)