From 7f801388debcfd18b7f0214372642c153040f4a5 Mon Sep 17 00:00:00 2001 From: dmchen Date: Mon, 29 Jul 2024 05:42:57 +0000 Subject: [PATCH] fix/TD-30989 --- source/libs/monitorfw/src/taos_collector.c | 8 ++--- .../monitorfw/src/taos_collector_registry.c | 18 +++++------ source/libs/monitorfw/src/taos_map.c | 21 ++++++------ source/libs/monitorfw/src/taos_metric.c | 10 +++--- .../monitorfw/src/taos_metric_formatter.c | 4 +-- .../src/taos_metric_formatter_custom.c | 32 +++++++++---------- .../libs/monitorfw/src/taos_metric_sample.c | 2 +- source/libs/monitorfw/src/taos_monitor_util.c | 4 +-- .../libs/monitorfw/src/taos_string_builder.c | 2 +- 9 files changed, 51 insertions(+), 50 deletions(-) diff --git a/source/libs/monitorfw/src/taos_collector.c b/source/libs/monitorfw/src/taos_collector.c index 8be4edaef9..01e37b6d76 100644 --- a/source/libs/monitorfw/src/taos_collector.c +++ b/source/libs/monitorfw/src/taos_collector.c @@ -39,18 +39,18 @@ taos_collector_t *taos_collector_new(const char *name) { self->name = taos_strdup(name); self->metrics = taos_map_new(); if (self->metrics == NULL) { - taos_collector_destroy(self); + (void)taos_collector_destroy(self); return NULL; } r = taos_map_set_free_value_fn(self->metrics, &taos_metric_free_generic); if (r) { - taos_collector_destroy(self); + (void)taos_collector_destroy(self); return NULL; } self->collect_fn = &taos_collector_default_collect; self->string_builder = taos_string_builder_new(); if (self->string_builder == NULL) { - taos_collector_destroy(self); + (void)taos_collector_destroy(self); return NULL; } self->proc_limits_file_path = NULL; @@ -93,7 +93,7 @@ int taos_collector_destroy_generic(void *gen) { void taos_collector_free_generic(void *gen) { taos_collector_t *self = (taos_collector_t *)gen; - taos_collector_destroy(self); + (void)taos_collector_destroy(self); } int taos_collector_set_collect_fn(taos_collector_t *self, taos_collect_fn *fn) { diff --git a/source/libs/monitorfw/src/taos_collector_registry.c b/source/libs/monitorfw/src/taos_collector_registry.c index 0c8385791d..88f56549e5 100644 --- a/source/libs/monitorfw/src/taos_collector_registry.c +++ b/source/libs/monitorfw/src/taos_collector_registry.c @@ -50,8 +50,8 @@ taos_collector_registry_t *taos_collector_registry_new(const char *name) { self->name = taos_strdup(name); self->collectors = taos_map_new(); - taos_map_set_free_value_fn(self->collectors, &taos_collector_free_generic); - taos_map_set(self->collectors, "default", taos_collector_new("default")); + (void)taos_map_set_free_value_fn(self->collectors, &taos_collector_free_generic); + if (taos_map_set(self->collectors, "default", taos_collector_new("default")) != 0) return NULL; self->metric_formatter = taos_metric_formatter_new(); self->string_builder = taos_string_builder_new(); @@ -237,15 +237,15 @@ int taos_collector_registry_clear_batch(taos_collector_registry_t *self){ } const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, char *ts, char *format, char** prom_str) { - taos_metric_formatter_clear(self->metric_formatter); - + if (taos_metric_formatter_clear(self->metric_formatter) != 0) return NULL; + SJson* pJson = tjsonCreateArray(); SJson* item = tjsonCreateObject(); - tjsonAddItemToArray(pJson, item); - tjsonAddStringToObject(item, "ts", ts); - tjsonAddDoubleToObject(item, "protocol", 2); + (void)tjsonAddItemToArray(pJson, item); + (void)tjsonAddStringToObject(item, "ts", ts); + (void)tjsonAddDoubleToObject(item, "protocol", 2); SJson* array = tjsonCreateArray(); - tjsonAddItemToObject(item, "tables", array); + (void)tjsonAddItemToObject(item, "tables", array); if(taos_metric_formatter_load_metrics_new(self->metric_formatter, self->collectors, ts, format, array) != 0){ TAOS_LOG("failed to load metrics"); @@ -304,7 +304,7 @@ 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); + (void)taos_string_builder_destroy(tmp_builder); } return NULL; diff --git a/source/libs/monitorfw/src/taos_map.c b/source/libs/monitorfw/src/taos_map.c index 55aaabf1a7..64d5475af2 100644 --- a/source/libs/monitorfw/src/taos_map.c +++ b/source/libs/monitorfw/src/taos_map.c @@ -59,7 +59,7 @@ int taos_map_node_destroy(taos_map_node_t *self) { void taos_map_node_free(void *item) { taos_map_node_t *map_node = (taos_map_node_t *)item; - taos_map_node_destroy(map_node); + (void)taos_map_node_destroy(map_node); } taos_linked_list_compare_t taos_map_node_compare(void *item_a, void *item_b) { @@ -87,7 +87,7 @@ taos_map_t *taos_map_new() { // we will only have to deallocate each key once. That will happen on taos_map_node_destroy. r = taos_linked_list_set_free_fn(self->keys, taos_linked_list_no_op_free); if (r) { - taos_map_destroy(self); + (void)taos_map_destroy(self); return NULL; } @@ -98,12 +98,12 @@ taos_map_t *taos_map_new() { self->addrs[i] = taos_linked_list_new(); r = taos_linked_list_set_free_fn(self->addrs[i], taos_map_node_free); if (r) { - taos_map_destroy(self); + (void)taos_map_destroy(self); return NULL; } r = taos_linked_list_set_compare_fn(self->addrs[i], taos_map_node_compare); if (r) { - taos_map_destroy(self); + (void)taos_map_destroy(self); return NULL; } } @@ -112,7 +112,7 @@ taos_map_t *taos_map_new() { r = pthread_rwlock_init(self->rwlock, NULL); if (r) { TAOS_LOG(TAOS_PTHREAD_RWLOCK_INIT_ERROR); - taos_map_destroy(self); + (void)taos_map_destroy(self); return NULL; } @@ -188,12 +188,12 @@ static void *taos_map_get_internal(const char *key, size_t *size, size_t *max_si taos_map_node_t *current_map_node = (taos_map_node_t *)current_node->item; taos_linked_list_compare_t result = taos_linked_list_compare(list, current_map_node, temp_map_node); if (result == TAOS_EQUAL) { - taos_map_node_destroy(temp_map_node); + (void)taos_map_node_destroy(temp_map_node); temp_map_node = NULL; return current_map_node->value; } } - taos_map_node_destroy(temp_map_node); + (void)taos_map_node_destroy(temp_map_node); temp_map_node = NULL; return NULL; } @@ -248,8 +248,8 @@ static int taos_map_set_internal(const char *key, void *value, size_t *size, siz return 0; } } - taos_linked_list_append(list, map_node); - taos_linked_list_append(keys, (char *)map_node->key); + if (taos_linked_list_append(list, map_node) != 0) return 1; + if (taos_linked_list_append(keys, (char *)map_node->key) != 0) return 1; (*size)++; return 0; } @@ -311,7 +311,8 @@ int taos_map_ensure_space(taos_map_t *self) { self->addrs[i] = NULL; } // Destroy the collection of keys in the map - taos_linked_list_destroy(self->keys); + r = taos_linked_list_destroy(self->keys); + if (r) return r; self->keys = NULL; // Deallocate the backbone of the map diff --git a/source/libs/monitorfw/src/taos_metric.c b/source/libs/monitorfw/src/taos_metric.c index 056bf131f2..f31cef79b0 100644 --- a/source/libs/monitorfw/src/taos_metric.c +++ b/source/libs/monitorfw/src/taos_metric.c @@ -49,12 +49,12 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, for (int i = 0; i < label_key_count; i++) { if (strcmp(label_keys[i], "le") == 0) { TAOS_LOG(TAOS_METRIC_INVALID_LABEL_NAME); - taos_metric_destroy(self); + (void)taos_metric_destroy(self); return NULL; } if (strcmp(label_keys[i], "quantile") == 0) { TAOS_LOG(TAOS_METRIC_INVALID_LABEL_NAME); - taos_metric_destroy(self); + (void)taos_metric_destroy(self); return NULL; } k[i] = taos_strdup(label_keys[i]); @@ -68,14 +68,14 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, } else { r = taos_map_set_free_value_fn(self->samples, &taos_metric_sample_free_generic); if (r) { - taos_metric_destroy(self); + (void)taos_metric_destroy(self); return NULL; } } self->formatter = taos_metric_formatter_new(); if (self->formatter == NULL) { - taos_metric_destroy(self); + (void)taos_metric_destroy(self); return NULL; } self->rwlock = (pthread_rwlock_t *)taos_malloc(sizeof(pthread_rwlock_t)); @@ -140,7 +140,7 @@ int taos_metric_destroy_generic(void *item) { void taos_metric_free_generic(void *item) { taos_metric_t *self = (taos_metric_t *)item; - taos_metric_destroy(self); + (void)taos_metric_destroy(self); } taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const char **label_values) { diff --git a/source/libs/monitorfw/src/taos_metric_formatter.c b/source/libs/monitorfw/src/taos_metric_formatter.c index 5f34edf3e6..e57c809815 100644 --- a/source/libs/monitorfw/src/taos_metric_formatter.c +++ b/source/libs/monitorfw/src/taos_metric_formatter.c @@ -34,12 +34,12 @@ taos_metric_formatter_t *taos_metric_formatter_new() { taos_metric_formatter_t *self = (taos_metric_formatter_t *)taos_malloc(sizeof(taos_metric_formatter_t)); self->string_builder = taos_string_builder_new(); if (self->string_builder == NULL) { - taos_metric_formatter_destroy(self); + (void)taos_metric_formatter_destroy(self); return NULL; } self->err_builder = taos_string_builder_new(); if (self->err_builder == NULL) { - taos_metric_formatter_destroy(self); + (void)taos_metric_formatter_destroy(self); return NULL; } return self; diff --git a/source/libs/monitorfw/src/taos_metric_formatter_custom.c b/source/libs/monitorfw/src/taos_metric_formatter_custom.c index 553227c801..0287641311 100644 --- a/source/libs/monitorfw/src/taos_metric_formatter_custom.c +++ b/source/libs/monitorfw/src/taos_metric_formatter_custom.c @@ -88,17 +88,17 @@ int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_me char* value = *(pair + 1); SJson* tag = tjsonCreateObject(); - tjsonAddStringToObject(tag, "name", key); - tjsonAddStringToObject(tag, "value", value); + (void)tjsonAddStringToObject(tag, "name", key); + (void)tjsonAddStringToObject(tag, "value", value); - tjsonAddItemToArray(arrayTag, tag); + (void)tjsonAddItemToArray(arrayTag, tag); } - tjsonAddItemToObject(item, "tags", arrayTag); + (void)tjsonAddItemToObject(item, "tags", arrayTag); metrics = tjsonCreateArray(); - tjsonAddItemToObject(item, "metrics", metrics); + (void)tjsonAddItemToObject(item, "metrics", metrics); - tjsonAddItemToArray(arrayMetricGroups, item); + (void)tjsonAddItemToArray(arrayMetricGroups, item); } else{ metrics = tjsonGetObjectItem(item, "metrics"); @@ -109,20 +109,20 @@ int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_me taosMemoryFreeClear(keyvalues); SJson* metric = tjsonCreateObject(); - tjsonAddStringToObject(metric, "name", metricName); - + (void)tjsonAddStringToObject(metric, "name", metricName); + double old_value = 0; #define USE_EXCHANGE #ifdef USE_EXCHANGE - taos_metric_sample_exchange(sample, 0, &old_value); + (void)taos_metric_sample_exchange(sample, 0, &old_value); #else old_value = sample->r_value; taos_metric_sample_set(sample, 0); #endif - tjsonAddDoubleToObject(metric, "value", old_value); - tjsonAddDoubleToObject(metric, "type", metric_type); - tjsonAddItemToArray(metrics, metric); + (void)tjsonAddDoubleToObject(metric, "value", old_value); + (void)tjsonAddDoubleToObject(metric, "type", metric_type); + (void)tjsonAddItemToArray(metrics, metric); return 0; } @@ -150,7 +150,7 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me SJson* table = tjsonGetArrayItem(tableArray, i); char tableName[MONITOR_TABLENAME_LEN] = {0}; - tjsonGetStringValue(table, "name", tableName); + (void)tjsonGetStringValue(table, "name", tableName); if(strcmp(tableName, arr[0]) == 0){ isFound = true; arrayMetricGroups = tjsonGetObjectItem(table, "metric_groups"); @@ -161,10 +161,10 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me if(!isFound){ table = tjsonCreateObject(); - tjsonAddStringToObject(table, "name", arr[0]); + (void)tjsonAddStringToObject(table, "name", arr[0]); arrayMetricGroups = tjsonCreateArray(); - tjsonAddItemToObject(table, "metric_groups", arrayMetricGroups); + (void)tjsonAddItemToObject(table, "metric_groups", arrayMetricGroups); } int32_t sample_count = 0; @@ -183,7 +183,7 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me } if(!isFound && sample_count > 0){ - tjsonAddItemToArray(tableArray, table); + (void)tjsonAddItemToArray(tableArray, table); } else{ if(table != NULL) tjsonDelete(table); diff --git a/source/libs/monitorfw/src/taos_metric_sample.c b/source/libs/monitorfw/src/taos_metric_sample.c index 4688672835..ccddefa17e 100644 --- a/source/libs/monitorfw/src/taos_metric_sample.c +++ b/source/libs/monitorfw/src/taos_metric_sample.c @@ -63,7 +63,7 @@ int taos_metric_sample_destroy_generic(void *gen) { void taos_metric_sample_free_generic(void *gen) { taos_metric_sample_t *self = (taos_metric_sample_t *)gen; - taos_metric_sample_destroy(self); + (void)taos_metric_sample_destroy(self); } int taos_metric_sample_add(taos_metric_sample_t *self, double r_value) { diff --git a/source/libs/monitorfw/src/taos_monitor_util.c b/source/libs/monitorfw/src/taos_monitor_util.c index d338215426..2285ed9e71 100644 --- a/source/libs/monitorfw/src/taos_monitor_util.c +++ b/source/libs/monitorfw/src/taos_monitor_util.c @@ -84,10 +84,10 @@ bool taos_monitor_is_match(const SJson* tags, char** pairs, int32_t count) { SJson* item = tjsonGetArrayItem(tags, i); char item_name[MONITOR_TAG_NAME_LEN] = {0}; - tjsonGetStringValue(item, "name", item_name); + (void)tjsonGetStringValue(item, "name", item_name); char item_value[MONITOR_TAG_VALUE_LEN] = {0}; - tjsonGetStringValue(item, "value", item_value); + (void)tjsonGetStringValue(item, "value", item_value); bool isfound = false; for(int32_t j = 0; j < count; j++){ diff --git a/source/libs/monitorfw/src/taos_string_builder.c b/source/libs/monitorfw/src/taos_string_builder.c index e1bfa4142c..208f3f6d51 100644 --- a/source/libs/monitorfw/src/taos_string_builder.c +++ b/source/libs/monitorfw/src/taos_string_builder.c @@ -44,7 +44,7 @@ taos_string_builder_t *taos_string_builder_new(void) { self->init_size = TAOS_STRING_BUILDER_INIT_SIZE; r = taos_string_builder_init(self); if (r) { - taos_string_builder_destroy(self); + (void)taos_string_builder_destroy(self); return NULL; }