From 2ae72aedb9e979ee3d5f3c16a41fa676fc0558af Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Fri, 30 Aug 2024 12:03:03 +0200 Subject: [PATCH] decode_prometheus_remote_write: fixed dangling reference and leaks Signed-off-by: Leonardo Alminana --- src/cmt_decode_prometheus_remote_write.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cmt_decode_prometheus_remote_write.c b/src/cmt_decode_prometheus_remote_write.c index 4aa91e6..3adecce 100644 --- a/src/cmt_decode_prometheus_remote_write.c +++ b/src/cmt_decode_prometheus_remote_write.c @@ -413,6 +413,8 @@ static int decode_histogram_points(struct cmt *cmt, destroy_label_list(&metric->labels); free(metric); + + return CMT_DECODE_PROMETHEUS_REMOTE_WRITE_DECODE_ERROR; } else { cfl_list_add(&metric->_head, &map->metrics); @@ -438,7 +440,13 @@ static int decode_histogram_points(struct cmt *cmt, } } else { - free(metric); + if (static_metric_detected == CMT_FALSE) { + destroy_label_list(&metric->labels); + + cfl_list_del(&metric->_head); + + free(metric); + } return CMT_DECODE_PROMETHEUS_REMOTE_WRITE_DECODE_ERROR; } @@ -452,7 +460,13 @@ static int decode_histogram_points(struct cmt *cmt, metric->hist_count = hist->count_float; } else { - free(metric); + if (static_metric_detected == CMT_FALSE) { + destroy_label_list(&metric->labels); + + cfl_list_del(&metric->_head); + + free(metric); + } return CMT_DECODE_PROMETHEUS_REMOTE_WRITE_DECODE_ERROR; }