Skip to content

Commit

Permalink
in_opentelemetry: fix memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Dec 18, 2023
1 parent 2e991ec commit ca7bb0d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions plugins/in_opentelemetry/opentelemetry_prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,15 @@ static int binary_payload_to_msgpack(struct flb_log_event_encoder *encoder,
input_logs = opentelemetry__proto__collector__logs__v1__export_logs_service_request__unpack(NULL, in_size, in_buf);
if (input_logs == NULL) {
flb_error("[otel] Failed to unpack input logs");
return -1;
ret = -1;
goto binary_payload_to_msgpack_end;
}

resource_logs = input_logs->resource_logs;
if (resource_logs == NULL) {
flb_error("[otel] No resource logs found");
return -1;
ret = -1;
goto binary_payload_to_msgpack_end;
}

for (resource_logs_index = 0; resource_logs_index < input_logs->n_resource_logs; resource_logs_index++) {
Expand All @@ -425,7 +427,8 @@ static int binary_payload_to_msgpack(struct flb_log_event_encoder *encoder,

if (resource_log->n_scope_logs > 0 && scope_logs == NULL) {
flb_error("[otel] No scope logs found");
return -1;
ret = -1;
goto binary_payload_to_msgpack_end;
}

for (scope_log_index = 0; scope_log_index < resource_log->n_scope_logs; scope_log_index++) {
Expand All @@ -434,7 +437,8 @@ static int binary_payload_to_msgpack(struct flb_log_event_encoder *encoder,

if (log_records == NULL) {
flb_error("[otel] No log records found");
return -1;
ret = -1;
goto binary_payload_to_msgpack_end;
}

for (log_record_index=0; log_record_index < scope_log->n_log_records; log_record_index++) {
Expand Down Expand Up @@ -499,16 +503,22 @@ static int binary_payload_to_msgpack(struct flb_log_event_encoder *encoder,
}
else {
flb_error("[otel] marshalling error");

msgpack_sbuffer_destroy(&buffer);

return -1;
goto binary_payload_to_msgpack_end;
}
}
}
}

binary_payload_to_msgpack_end:
msgpack_sbuffer_destroy(&buffer);
if (input_logs) {
opentelemetry__proto__collector__logs__v1__export_logs_service_request__free_unpacked(
input_logs, NULL);
}

if (ret != 0) {
return -1;
}

return 0;
}
Expand Down

0 comments on commit ca7bb0d

Please sign in to comment.