From f510f2961bac064f757072b881eac77404b6d34b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 27 Aug 2024 18:45:20 +0800 Subject: [PATCH] fix(query): fix memory leak. --- source/dnode/vnode/src/tsdb/tsdbFS2.c | 1 + source/dnode/vnode/src/tsdb/tsdbFSet2.c | 2 ++ source/dnode/vnode/src/tsdb/tsdbMergeTree.c | 24 +++++++++++++-------- source/libs/executor/src/exchangeoperator.c | 1 - source/libs/executor/src/mergeoperator.c | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 6dec456be7..7a51f9ebd4 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -1025,6 +1025,7 @@ int32_t tsdbFSCreateRefSnapshotWithoutLock(STFileSystem *fs, TFileSetArray **fse if (code) { TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear); + taosMemoryFree(fsetArr[0]); fsetArr[0] = NULL; } return code; diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.c b/source/dnode/vnode/src/tsdb/tsdbFSet2.c index 720a9b9791..de62ce63a0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFSet2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.c @@ -576,12 +576,14 @@ int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fs SSttLvl *lvl; code = tsdbSttLvlInitRef(pTsdb, lvl1, &lvl); if (code) { + taosMemoryFree(lvl); tsdbTFileSetClear(fset); return code; } code = TARRAY2_APPEND(fset[0]->lvlArr, lvl); if (code) { + taosMemoryFree(lvl); tsdbTFileSetClear(fset); return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 21c5d33ec9..4526fe4cd4 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -86,14 +86,19 @@ void destroySttBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo) { pInfo->sttBlockIndex = -1; pInfo->pin = false; - if (pLoadInfo->info.pCount != NULL) { - taosArrayDestroy(pLoadInfo->info.pUid); - taosArrayDestroyEx(pLoadInfo->info.pFirstKey, freeItem); - taosArrayDestroyEx(pLoadInfo->info.pLastKey, freeItem); - taosArrayDestroy(pLoadInfo->info.pCount); - taosArrayDestroy(pLoadInfo->info.pFirstTs); - taosArrayDestroy(pLoadInfo->info.pLastTs); - } + taosArrayDestroy(pLoadInfo->info.pUid); + taosArrayDestroyEx(pLoadInfo->info.pFirstKey, freeItem); + taosArrayDestroyEx(pLoadInfo->info.pLastKey, freeItem); + taosArrayDestroy(pLoadInfo->info.pCount); + taosArrayDestroy(pLoadInfo->info.pFirstTs); + taosArrayDestroy(pLoadInfo->info.pLastTs); + + pLoadInfo->info.pUid = NULL; + pLoadInfo->info.pFirstKey = NULL; + pLoadInfo->info.pLastKey = NULL; + pLoadInfo->info.pCount = NULL; + pLoadInfo->info.pFirstTs = NULL; + pLoadInfo->info.pLastTs = NULL; taosArrayDestroy(pLoadInfo->aSttBlk); taosMemoryFree(pLoadInfo); @@ -834,7 +839,6 @@ int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool *hasNext) { int32_t lino = 0; *hasNext = false; - terrno = 0; // no qualified last file block in current file, no need to fetch row if (pIter->pSttBlk == NULL) { @@ -843,6 +847,7 @@ int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool *hasNext) { code = loadLastBlock(pIter, idStr, &pBlockData); if (pBlockData == NULL || code != TSDB_CODE_SUCCESS) { + lino = __LINE__; goto _exit; } @@ -888,6 +893,7 @@ int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool *hasNext) { if (iBlockL != pIter->iSttBlk) { code = loadLastBlock(pIter, idStr, &pBlockData); if ((pBlockData == NULL) || (code != 0)) { + lino = __LINE__; goto _exit; } diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 507fc5b154..4315624d97 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -459,7 +459,6 @@ _error: pOperator->info = NULL; destroyOperator(pOperator); } - pTaskInfo->code = code; return code; } diff --git a/source/libs/executor/src/mergeoperator.c b/source/libs/executor/src/mergeoperator.c index ae23b3c8d7..8391bfbe2a 100644 --- a/source/libs/executor/src/mergeoperator.c +++ b/source/libs/executor/src/mergeoperator.c @@ -587,6 +587,7 @@ int32_t createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size_t numS SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); SSDataBlock* pInputBlock = createDataBlockFromDescNode(pChildNode->pOutputDataBlockDesc); TSDB_CHECK_NULL(pInputBlock, code, lino, _error, terrno); + pSortMergeInfo->pInputBlock = pInputBlock; initResultSizeInfo(&pOperator->resultInfo, 1024); code = blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); @@ -599,7 +600,6 @@ int32_t createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size_t numS pSortMergeInfo->bufPageSize = getProperSortPageSize(rowSize, numOfCols); pSortMergeInfo->sortBufSize = pSortMergeInfo->bufPageSize * (numStreams + 1); // one additional is reserved for merged result. - pSortMergeInfo->pInputBlock = pInputBlock; code = extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pSortMergeInfo->matchInfo); if (code != TSDB_CODE_SUCCESS) {