Merge pull request #25957 from taosdata/fix/TD-30307-3.0

fix/TD-30307
This commit is contained in:
Hongze Cheng 2024-05-29 18:53:59 +08:00 committed by GitHub
commit cd74a7e8e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 12 deletions

View File

@ -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 * @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 * @brief API PRIVATE Returns the item at the head of the list or NULL if not present

View File

@ -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) { taos_collector_t *taos_collector_new(const char *name) {
int r = 0; int r = 0;
taos_collector_t *self = (taos_collector_t *)taos_malloc(sizeof(taos_collector_t)); 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->name = taos_strdup(name);
self->metrics = taos_map_new(); self->metrics = taos_map_new();
if (self->metrics == NULL) { if (self->metrics == NULL) {
@ -66,9 +68,11 @@ int taos_collector_destroy(taos_collector_t *self) {
if (r) ret = r; if (r) ret = r;
self->metrics = NULL; self->metrics = NULL;
r = taos_string_builder_destroy(self->string_builder); if(self->string_builder != NULL){
if (r) ret = r; r = taos_string_builder_destroy(self->string_builder);
self->string_builder = NULL; if (r) ret = r;
self->string_builder = NULL;
}
taos_free((char *)self->name); taos_free((char *)self->name);
self->name = NULL; self->name = NULL;

View File

@ -59,6 +59,7 @@ taos_collector_registry_t *taos_collector_registry_new(const char *name) {
r = pthread_rwlock_init(self->lock, NULL); r = pthread_rwlock_init(self->lock, NULL);
if (r) { if (r) {
TAOS_LOG("failed to initialize rwlock"); TAOS_LOG("failed to initialize rwlock");
taos_free(self);
return NULL; return NULL;
} }
return self; return self;
@ -301,6 +302,9 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self,
_OVER: _OVER:
tjsonDelete(pJson); tjsonDelete(pJson);
if(tmp_builder != NULL){
taos_string_builder_destroy(tmp_builder);
}
return NULL; return NULL;
} }

View File

@ -117,6 +117,7 @@ int taos_linked_list_push(taos_linked_list_t *self, void *item) {
return 0; return 0;
} }
/*
void *taos_linked_list_pop(taos_linked_list_t *self) { void *taos_linked_list_pop(taos_linked_list_t *self) {
TAOS_ASSERT(self != NULL); TAOS_ASSERT(self != NULL);
if (self == NULL) return NULL; if (self == NULL) return NULL;
@ -141,6 +142,7 @@ void *taos_linked_list_pop(taos_linked_list_t *self) {
} }
return item; return item;
} }
*/
int taos_linked_list_remove(taos_linked_list_t *self, void *item) { int taos_linked_list_remove(taos_linked_list_t *self, void *item) {
TAOS_ASSERT(self != NULL); TAOS_ASSERT(self != NULL);

View File

@ -90,7 +90,7 @@ taos_map_t *taos_map_new() {
return NULL; 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; self->free_value_fn = destroy_map_node_value_no_op;
for (int i = 0; i < self->max_size; i++) { 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; if (r) return r;
// Create a new array of addrs // 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 // Initialize the new array
for (int i = 0; i < new_max; i++) { for (int i = 0; i < new_max; i++) {

View File

@ -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) { size_t label_key_count, const char **label_keys) {
int r = 0; int r = 0;
taos_metric_t *self = (taos_metric_t *)taos_malloc(sizeof(taos_metric_t)); 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; self->type = metric_type;
int len = strlen(name) + 1; int len = strlen(name) + 1;
self->name = taos_malloc(len); 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); r = pthread_rwlock_init(self->rwlock, NULL);
if (r) { if (r) {
TAOS_LOG(TAOS_PTHREAD_RWLOCK_INIT_ERROR); TAOS_LOG(TAOS_PTHREAD_RWLOCK_INIT_ERROR);
taos_free(self);
return NULL; return NULL;
} }
return self; return self;
@ -91,9 +94,11 @@ int taos_metric_destroy(taos_metric_t *self) {
int r = 0; int r = 0;
int ret = 0; int ret = 0;
r = taos_map_destroy(self->samples); if(self->samples != NULL){
self->samples = NULL; r = taos_map_destroy(self->samples);
if (r) ret = r; self->samples = NULL;
if (r) ret = r;
}
r = taos_metric_formatter_destroy(self->formatter); r = taos_metric_formatter_destroy(self->formatter);
self->formatter = NULL; self->formatter = NULL;
@ -152,8 +157,7 @@ taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const
return NULL; return NULL;
// Get l_value // Get l_value
r = taos_metric_formatter_load_l_value(self->formatter, self->name, NULL, self->label_key_count, self->label_keys, r = taos_metric_formatter_load_l_value(self->formatter, self->name, NULL, self->label_key_count, self->label_keys, label_values);
label_values);
if (r) { if (r) {
TAOS_METRIC_SAMPLE_FROM_LABELS_HANDLE_UNLOCK(); 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); sample = taos_metric_sample_new(self->type, l_value, 0.0);
r = taos_map_set(self->samples, l_value, sample); r = taos_map_set(self->samples, l_value, sample);
if (r) { if (r) {
taos_free((void *)l_value);
TAOS_METRIC_SAMPLE_FROM_LABELS_HANDLE_UNLOCK(); 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); taos_free((void *)l_value);
return sample; return sample;
} }