From 5c3e1e6150d50384c2a03bbadcb2c153a21232ec Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Thu, 29 Aug 2024 11:44:02 +0200 Subject: [PATCH] decode_statsd: fixed resource leaks Signed-off-by: Leonardo Alminana --- src/cmt_decode_statsd.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/cmt_decode_statsd.c b/src/cmt_decode_statsd.c index 7a8814a..43b2213 100644 --- a/src/cmt_decode_statsd.c +++ b/src/cmt_decode_statsd.c @@ -157,7 +157,14 @@ static int decode_labels(struct cmt *cmt, } label_k = cfl_sds_create_len(label_kv, colon - label_kv); if (label_k == NULL) { + for (label_index = 0 ; label_index < 128 ; label_index++) { + if (value_index_list[label_index] != NULL) { + cfl_sds_destroy(value_index_list[label_index]); + } + } + free(value_index_list); + if (kvs != NULL) { cfl_utils_split_free(kvs); } @@ -167,7 +174,15 @@ static int decode_labels(struct cmt *cmt, label_v = cfl_sds_create_len(colon + 1, strlen(label_kv) - strlen(label_k) - 1); if (label_v == NULL) { cfl_sds_destroy(label_k); + + for (label_index = 0 ; label_index < 128 ; label_index++) { + if (value_index_list[label_index] != NULL) { + cfl_sds_destroy(value_index_list[label_index]); + } + } + free(value_index_list); + if (kvs != NULL) { cfl_utils_split_free(kvs); } @@ -190,7 +205,15 @@ static int decode_labels(struct cmt *cmt, if (label_index > 127) { cfl_sds_destroy(label_k); cfl_sds_destroy(label_v); + + for (label_index = 0 ; label_index < 128 ; label_index++) { + if (value_index_list[label_index] != NULL) { + cfl_sds_destroy(value_index_list[label_index]); + } + } + free(value_index_list); + if (kvs != NULL) { cfl_utils_split_free(kvs); } @@ -227,20 +250,18 @@ static int decode_labels(struct cmt *cmt, } } - for (map_label_index = 0 ; - result == CMT_DECODE_STATSD_SUCCESS && - map_label_index < map_label_count ; - map_label_index++) { - label_v = (cfl_sds_t) value_index_list[map_label_index]; - cfl_sds_destroy(label_v); + for (label_index = 0 ; label_index < 128 ; label_index++) { + if (value_index_list[label_index] != NULL) { + cfl_sds_destroy(value_index_list[label_index]); + } } + free(value_index_list); + if (kvs != NULL) { cfl_utils_split_free(kvs); } - free(value_index_list); - return result; }