diff --git a/src/cmt_encode_opentelemetry.c b/src/cmt_encode_opentelemetry.c index 8c93418..8378bc8 100644 --- a/src/cmt_encode_opentelemetry.c +++ b/src/cmt_encode_opentelemetry.c @@ -711,13 +711,13 @@ static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_binary_to_ result->bytes_value.len = cfl_sds_len(value->data.as_bytes); result->bytes_value.data = calloc(result->bytes_value.len, sizeof(char)); - if (result->bytes_value.data == NULL) { + if (result->bytes_value.data) { + memcpy(result->bytes_value.data, value->data.as_bytes, result->bytes_value.len); + } + else { otlp_any_value_destroy(result); - result = NULL; } - - memcpy(result->bytes_value.data, value->data.as_bytes, result->bytes_value.len); } return result; diff --git a/tests/prometheus_parser.c b/tests/prometheus_parser.c index a6407a1..461cdec 100644 --- a/tests/prometheus_parser.c +++ b/tests/prometheus_parser.c @@ -1669,6 +1669,7 @@ void test_issue_fluent_bit_9267() { char errbuf[256]; int status; + cfl_sds_t result = NULL; struct cmt *cmt; struct cmt_decode_prometheus_parse_opts opts; memset(&opts, 0, sizeof(opts)); @@ -1688,6 +1689,7 @@ void test_issue_fluent_bit_9267() if (cmt != NULL) { cmt_decode_prometheus_destroy(cmt); } + cmt_decode_prometheus_destroy(cmt); cfl_sds_destroy(in_buf); }