From c9286fed25225b40e9b2184f3c080d5900c376e5 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 30 Sep 2022 13:03:25 +0800 Subject: [PATCH] fix(query): fix memory leak. --- source/dnode/vnode/inc/vnode.h | 2 +- source/dnode/vnode/src/tsdb/tsdbCacheRead.c | 4 ++-- source/libs/executor/src/cachescanoperator.c | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 6ba10641f5..3e086de097 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -153,7 +153,7 @@ uint64_t getReaderMaxVersion(STsdbReader *pReader); int32_t tsdbCacherowsReaderOpen(void *pVnode, int32_t type, SArray *pTableIdList, int32_t numOfCols, void **pReader); int32_t tsdbRetrieveCacheRows(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds, SArray *pTableUids); -int32_t tsdbCacherowsReaderClose(void *pReader); +void* tsdbCacherowsReaderClose(void *pReader); int32_t tsdbGetTableSchema(SVnode *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid); void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity); diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index 5f981649f3..7a000253d5 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -101,7 +101,7 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList return TSDB_CODE_SUCCESS; } -int32_t tsdbCacherowsReaderClose(void* pReader) { +void* tsdbCacherowsReaderClose(void* pReader) { SCacheRowsReader* p = pReader; if (p->pSchema != NULL) { @@ -114,7 +114,7 @@ int32_t tsdbCacherowsReaderClose(void* pReader) { } taosMemoryFree(pReader); - return TSDB_CODE_SUCCESS; + return NULL; } static int32_t doExtractCacheRow(SCacheRowsReader* pr, SLRUCache* lruCache, uint64_t uid, STSRow** pRow, diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index 94d9d0cadb..1b7448712e 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -207,7 +207,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { } } - tsdbCacherowsReaderClose(pInfo->pLastrowReader); + pInfo->pLastrowReader = tsdbCacherowsReaderClose(pInfo->pLastrowReader); return pInfo->pRes; } } @@ -220,6 +220,15 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { void destroyLastrowScanOperator(void* param) { SLastrowScanInfo* pInfo = (SLastrowScanInfo*)param; blockDataDestroy(pInfo->pRes); + blockDataDestroy(pInfo->pBufferredRes); + taosMemoryFree(pInfo->pSlotIds); + taosArrayDestroy(pInfo->pUidList); + taosArrayDestroy(pInfo->pColMatchInfo); + + if (pInfo->pLastrowReader != NULL) { + pInfo->pLastrowReader = tsdbCacherowsReaderClose(pInfo->pLastrowReader); + } + taosMemoryFreeClear(param); } -- GitLab