diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 35b25cb85a..2abf292e73 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -143,8 +143,8 @@ void vmCleanExpriedSamples(SVnodeMgmt *pMgmt) { } } (void)taosThreadRwlockUnlock(&pMgmt->lock); - taosMemoryFree(vgroup_ids); - taosMemoryFree(keys); + if (vgroup_ids) taosMemoryFree(vgroup_ids); + if (keys) taosMemoryFree(keys); return; } diff --git a/source/libs/monitorfw/src/taos_counter.c b/source/libs/monitorfw/src/taos_counter.c index be5e1f781f..e60e5a5f3f 100644 --- a/source/libs/monitorfw/src/taos_counter.c +++ b/source/libs/monitorfw/src/taos_counter.c @@ -76,15 +76,21 @@ int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys, int32_t **vg return 1; } if (self->samples == NULL) return 1; + pthread_rwlock_rdlock(self->rwlock); taos_linked_list_t *key_list = self->samples->keys; *list_size = key_list->size; int r = 0; *vgroup_ids = (int32_t *)taos_malloc(*list_size * sizeof(int32_t)); - if (vgroup_ids == NULL) return 1; + if (vgroup_ids == NULL) { + pthread_rwlock_unlock(self->rwlock); + return 1; + } *keys = (char **)taos_malloc(*list_size * sizeof(char *)); - if (keys == NULL) return 1; + if (keys == NULL) { + pthread_rwlock_unlock(self->rwlock); + return 1; + } int index = 0; - pthread_rwlock_rdlock(self->rwlock); for (taos_linked_list_node_t *current_key = key_list->head; current_key != NULL; current_key = current_key->next) { char *key = (char *)current_key->item; int32_t vgroup_id = taos_metric_formatter_get_vgroup_id(key);