From 6af9f279bc923c14152f9f30da3ddf3e60b7c310 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 6 Sep 2024 17:01:17 +0800 Subject: [PATCH] fix(query): fix memory leak. --- source/dnode/vnode/src/tsdb/tsdbMergeTree.c | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index fc2b873054..0989b6f8ab 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -408,9 +408,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl for (int32_t k = startIndex; k < endIndex; ++k) { code = tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[k], &block); - if (code) { - return code; - } + QUERY_CHECK_CODE(code, lino, _end); int32_t i = 0; int32_t rows = block.numOfRecords; @@ -536,12 +534,15 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl } _end: - (void)tStatisBlockDestroy(&block); + (void) tStatisBlockDestroy(&block); + if (code != 0) { + tsdbError("%s error happens at:%s line number: %d, code:%s", id, __FUNCTION__, lino, tstrerror(code)); + } else { + double el = (taosGetTimestampUs() - st) / 1000.0; + pBlockLoadInfo->cost.statisElapsedTime += el; - double el = (taosGetTimestampUs() - st) / 1000.0; - pBlockLoadInfo->cost.statisElapsedTime += el; - - tsdbDebug("%s load %d statis blocks into buf, elapsed time:%.2fms", id, num, el); + tsdbDebug("%s load %d statis blocks into buf, elapsed time:%.2fms", id, num, el); + } return code; } @@ -953,6 +954,7 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF pMTree->pIter = NULL; pMTree->backward = pConf->backward; pMTree->idStr = pConf->idstr; + int32_t lino = 0; if (!pMTree->backward) { // asc tRBTreeCreate(&pMTree->rbt, tLDataIterCmprFn); @@ -1027,9 +1029,8 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF // let's record the time window for current table of uid in the stt files if (pSttDataInfo != NULL && numOfRows > 0) { void *px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range); - if (px == NULL) { - return terrno; - } + QUERY_CHECK_NULL(px, code, lino, _end, terrno); + pSttDataInfo->numOfRows += numOfRows; } } else {