From 6ce0afda81bd6608e66f4103749fbbd15bf55518 Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Tue, 9 Apr 2024 11:52:53 +0200 Subject: [PATCH] input_metric: fixed a double free Signed-off-by: Leonardo Alminana --- src/flb_input_metric.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/flb_input_metric.c b/src/flb_input_metric.c index 8b3652a85f9..9daf21ba037 100644 --- a/src/flb_input_metric.c +++ b/src/flb_input_metric.c @@ -64,14 +64,16 @@ static int input_metrics_append(struct flb_input_instance *ins, if (out_context != NULL) { /* Convert metrics to msgpack */ ret = cmt_encode_msgpack_create(out_context, &mt_buf, &mt_size); + + if (out_context != cmt) { + cmt_destroy(out_context); + } + if (ret != 0) { flb_plg_error(ins, "could not encode metrics"); - cmt_destroy(out_context); return -1; } - - cmt_destroy(out_context); } else { /* Convert metrics to msgpack */