diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index d3f4747a96d509ef9764661a7f4bc7e8c8ceaef4..f0a2694b608363518c76b63d2e1e674330fba2fa 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -2639,8 +2639,7 @@ int32_t tsdbGetTableGroupFromIdList(TSDB_REPO_T* tsdb, SArray* pTableIdList, STa pGroupInfo->pGroupList = taosArrayInit(1, POINTER_BYTES); SArray* group = taosArrayInit(1, sizeof(STableKeyInfo)); - int32_t i = 0; - for(; i < size; ++i) { + for(int32_t i = 0; i < size; ++i) { STableIdInfo *id = taosArrayGet(pTableIdList, i); STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), id->uid); @@ -2665,8 +2664,12 @@ int32_t tsdbGetTableGroupFromIdList(TSDB_REPO_T* tsdb, SArray* pTableIdList, STa return terrno; } - pGroupInfo->numOfTables = i; - taosArrayPush(pGroupInfo->pGroupList, &group); + pGroupInfo->numOfTables = taosArrayGetSize(group); + if (pGroupInfo->numOfTables > 0) { + taosArrayPush(pGroupInfo->pGroupList, &group); + } else { + taosArrayDestroy(group); + } return TSDB_CODE_SUCCESS; }