From 205e3ecf271027b458c7a0666be1f53309a8145a Mon Sep 17 00:00:00 2001 From: slzhou Date: Fri, 8 Dec 2023 21:49:36 +0800 Subject: [PATCH] fix: fix mem leak of block data buf --- source/libs/executor/src/scanoperator.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index efa054cb9a..77a4119be0 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -3233,15 +3233,16 @@ static int32_t saveSourceBlock(STmsSortRowIdInfo* pSortInfo, const SSDataBlock* return TSDB_CODE_OUT_OF_MEMORY; } blockDataToBuf(buf, pSrcBlock); - *pSzBlk = szBlk; - taosLSeekFile(pSortInfo->dataFile, pSortInfo->dataFileOffset, SEEK_SET); taosWriteFile(pSortInfo->dataFile, buf, szBlk); + taosMemoryFree(buf); STmsSortBlockInfo info = {.blkId = pSortInfo->blkId , .offset = pSortInfo->dataFileOffset, .length = szBlk}; taosLSeekFile(pSortInfo->idxFile, pSortInfo->blkId*sizeof(STmsSortBlockInfo), SEEK_SET); taosWriteFile(pSortInfo->idxFile, &info, sizeof(info)); + + *pSzBlk = szBlk; return 0; } @@ -3322,6 +3323,8 @@ static int32_t retrieveSourceBlock(STableMergeScanInfo* pInfo, int32_t blockId, taosReadFile(pSortInfo->dataFile, buf, blkInfo->length); SSDataBlock* pBlock = createOneDataBlock(pInfo->pReaderBlock, false); blockDataFromBuf(pBlock, buf); + taosMemoryFree(buf); + *ppBlock = pBlock; taosLRUCacheInsert(pSortInfo->pBlkDataCache, &blockId, sizeof(blockId), pBlock, 1, deleteBlockDataCache,