From 5283ca87edacbd0800d346ee01fae597be14a335 Mon Sep 17 00:00:00 2001 From: dmchen Date: Wed, 29 May 2024 03:08:15 +0000 Subject: [PATCH] fix/TD-30307 --- source/libs/monitorfw/inc/taos_linked_list_i.h | 2 +- source/libs/monitorfw/src/taos_collector.c | 10 +++++++--- .../monitorfw/src/taos_collector_registry.c | 4 ++++ source/libs/monitorfw/src/taos_linked_list.c | 2 ++ source/libs/monitorfw/src/taos_map.c | 4 ++-- source/libs/monitorfw/src/taos_metric.c | 18 ++++++++++++------ 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/source/libs/monitorfw/inc/taos_linked_list_i.h b/source/libs/monitorfw/inc/taos_linked_list_i.h index ed11a76427..015f8a57ad 100644 --- a/source/libs/monitorfw/inc/taos_linked_list_i.h +++ b/source/libs/monitorfw/inc/taos_linked_list_i.h @@ -47,7 +47,7 @@ int taos_linked_list_push(taos_linked_list_t *self, void *item); /** * @brief API PRIVATE Pop the first item off of the list */ -void *taos_linked_list_pop(taos_linked_list_t *self); +//void *taos_linked_list_pop(taos_linked_list_t *self); /** * @brief API PRIVATE Returns the item at the head of the list or NULL if not present diff --git a/source/libs/monitorfw/src/taos_collector.c b/source/libs/monitorfw/src/taos_collector.c index 17d324462c..414c02121d 100644 --- a/source/libs/monitorfw/src/taos_collector.c +++ b/source/libs/monitorfw/src/taos_collector.c @@ -33,6 +33,8 @@ taos_map_t *taos_collector_default_collect(taos_collector_t *self) { return self taos_collector_t *taos_collector_new(const char *name) { int r = 0; taos_collector_t *self = (taos_collector_t *)taos_malloc(sizeof(taos_collector_t)); + if (self == NULL) return NULL; + memset(self, 0, sizeof(taos_collector_t)); self->name = taos_strdup(name); self->metrics = taos_map_new(); if (self->metrics == NULL) { @@ -66,9 +68,11 @@ int taos_collector_destroy(taos_collector_t *self) { if (r) ret = r; self->metrics = NULL; - r = taos_string_builder_destroy(self->string_builder); - if (r) ret = r; - self->string_builder = NULL; + if(self->string_builder != NULL){ + r = taos_string_builder_destroy(self->string_builder); + if (r) ret = r; + self->string_builder = NULL; + } taos_free((char *)self->name); self->name = NULL; diff --git a/source/libs/monitorfw/src/taos_collector_registry.c b/source/libs/monitorfw/src/taos_collector_registry.c index c3ed0112c5..d4838ef301 100644 --- a/source/libs/monitorfw/src/taos_collector_registry.c +++ b/source/libs/monitorfw/src/taos_collector_registry.c @@ -59,6 +59,7 @@ taos_collector_registry_t *taos_collector_registry_new(const char *name) { r = pthread_rwlock_init(self->lock, NULL); if (r) { TAOS_LOG("failed to initialize rwlock"); + taos_free(self); return NULL; } return self; @@ -301,6 +302,9 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, _OVER: tjsonDelete(pJson); + if(tmp_builder != NULL){ + taos_string_builder_destroy(tmp_builder); + } return NULL; } diff --git a/source/libs/monitorfw/src/taos_linked_list.c b/source/libs/monitorfw/src/taos_linked_list.c index 675400a6fa..2becb08a07 100644 --- a/source/libs/monitorfw/src/taos_linked_list.c +++ b/source/libs/monitorfw/src/taos_linked_list.c @@ -117,6 +117,7 @@ int taos_linked_list_push(taos_linked_list_t *self, void *item) { return 0; } +/* void *taos_linked_list_pop(taos_linked_list_t *self) { TAOS_ASSERT(self != NULL); if (self == NULL) return NULL; @@ -141,6 +142,7 @@ void *taos_linked_list_pop(taos_linked_list_t *self) { } return item; } +*/ int taos_linked_list_remove(taos_linked_list_t *self, void *item) { TAOS_ASSERT(self != NULL); diff --git a/source/libs/monitorfw/src/taos_map.c b/source/libs/monitorfw/src/taos_map.c index 8f0b83884e..ffb7d000fc 100644 --- a/source/libs/monitorfw/src/taos_map.c +++ b/source/libs/monitorfw/src/taos_map.c @@ -90,7 +90,7 @@ taos_map_t *taos_map_new() { return NULL; } - self->addrs = taos_malloc(sizeof(taos_linked_list_t) * self->max_size); + self->addrs = taos_malloc(sizeof(taos_linked_list_t*) * self->max_size); self->free_value_fn = destroy_map_node_value_no_op; for (int i = 0; i < self->max_size; i++) { @@ -273,7 +273,7 @@ int taos_map_ensure_space(taos_map_t *self) { if (r) return r; // Create a new array of addrs - taos_linked_list_t **new_addrs = taos_malloc(sizeof(taos_linked_list_t) * new_max); + taos_linked_list_t **new_addrs = taos_malloc(sizeof(taos_linked_list_t*) * new_max); // Initialize the new array for (int i = 0; i < new_max; i++) { diff --git a/source/libs/monitorfw/src/taos_metric.c b/source/libs/monitorfw/src/taos_metric.c index 4e9af35f34..5cecbc927f 100644 --- a/source/libs/monitorfw/src/taos_metric.c +++ b/source/libs/monitorfw/src/taos_metric.c @@ -33,6 +33,8 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, size_t label_key_count, const char **label_keys) { int r = 0; taos_metric_t *self = (taos_metric_t *)taos_malloc(sizeof(taos_metric_t)); + if (self == NULL) return NULL; + memset(self, 0, sizeof(taos_metric_t)); self->type = metric_type; int len = strlen(name) + 1; self->name = taos_malloc(len); @@ -79,6 +81,7 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, r = pthread_rwlock_init(self->rwlock, NULL); if (r) { TAOS_LOG(TAOS_PTHREAD_RWLOCK_INIT_ERROR); + taos_free(self); return NULL; } return self; @@ -91,9 +94,11 @@ int taos_metric_destroy(taos_metric_t *self) { int r = 0; int ret = 0; - r = taos_map_destroy(self->samples); - self->samples = NULL; - if (r) ret = r; + if(self->samples != NULL){ + r = taos_map_destroy(self->samples); + self->samples = NULL; + if (r) ret = r; + } r = taos_metric_formatter_destroy(self->formatter); self->formatter = NULL; @@ -152,8 +157,7 @@ taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const return NULL; // Get l_value - r = taos_metric_formatter_load_l_value(self->formatter, self->name, NULL, self->label_key_count, self->label_keys, - label_values); + r = taos_metric_formatter_load_l_value(self->formatter, self->name, NULL, self->label_key_count, self->label_keys, label_values); if (r) { TAOS_METRIC_SAMPLE_FROM_LABELS_HANDLE_UNLOCK(); } @@ -170,10 +174,12 @@ taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const sample = taos_metric_sample_new(self->type, l_value, 0.0); r = taos_map_set(self->samples, l_value, sample); if (r) { + taos_free((void *)l_value); TAOS_METRIC_SAMPLE_FROM_LABELS_HANDLE_UNLOCK(); } } - pthread_rwlock_unlock(self->rwlock); + r = pthread_rwlock_unlock(self->rwlock); + if (r) TAOS_LOG(TAOS_PTHREAD_RWLOCK_UNLOCK_ERROR); taos_free((void *)l_value); return sample; }