From 8e97949a143d27ab7d15c73833687aca4d0f3f05 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 22 Jul 2020 17:04:05 +0800 Subject: [PATCH] [td-225] fix memory leaks. --- src/query/src/qResultbuf.c | 21 ++++++++++++++------- src/query/tests/CMakeLists.txt | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/query/src/qResultbuf.c b/src/query/src/qResultbuf.c index dff629e6a8..e54217f7e5 100644 --- a/src/query/src/qResultbuf.c +++ b/src/query/src/qResultbuf.c @@ -184,7 +184,10 @@ tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32 pResultBuf->inMemPages, pResultBuf->pageSize); } else { tdListPopNode(pResultBuf->pPageList, pn); - if (flushPageToDisk(pResultBuf, *(SPageInfo**)pn->data) != TSDB_CODE_SUCCESS) { + SPageInfo* d = *(SPageInfo**) pn->data; + tfree(pn); + + if (flushPageToDisk(pResultBuf, d) != TSDB_CODE_SUCCESS) { return NULL; } } @@ -275,6 +278,8 @@ tFilePage* getResBufPage(SDiskbasedResultBuf* pResultBuf, int32_t id) { fread(buf, (*pi)->info.length, 1, pResultBuf->file); (*pi)->pData = buf; + + tfree(pn); return (*pi)->pData; } } @@ -292,7 +297,6 @@ void releaseResBufPage(SDiskbasedResultBuf* pResultBuf, void* page) { T_REF_DEC(ppi); } - int32_t getNumOfRowsPerPage(SDiskbasedResultBuf* pResultBuf) { return pResultBuf->numOfRowsPerPage; } SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId) { @@ -325,15 +329,18 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf, void* handle) { unlink(pResultBuf->path); tfree(pResultBuf->path); -// size_t size = taosArrayGetSize(pResultBuf->list); -// for (int32_t i = 0; i < size; ++i) { -// SArray* pa = taosArrayGetP(pResultBuf->list, i); -// taosArrayDestroy(pa); -// } + SHashMutableIterator* iter = taosHashCreateIter(pResultBuf->idsTable); + while(taosHashIterNext(iter)) { + SArray** p = (SArray**) taosHashIterGet(iter); + taosArrayDestroy(*p); + } + + taosHashDestroyIter(iter); tdListFree(pResultBuf->pPageList); taosArrayDestroy(pResultBuf->emptyDummyIdList); taosHashCleanup(pResultBuf->idsTable); + taosHashCleanup(pResultBuf->all); tfree(pResultBuf); } diff --git a/src/query/tests/CMakeLists.txt b/src/query/tests/CMakeLists.txt index 0ae8600756..86715a4a0f 100644 --- a/src/query/tests/CMakeLists.txt +++ b/src/query/tests/CMakeLists.txt @@ -10,6 +10,6 @@ IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR}) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) - ADD_EXECUTABLE(queryTest ${SOURCE_LIST}) + ADD_EXECUTABLE(queryTest ./unitTest.cpp ./resultBufferTest.cpp) TARGET_LINK_LIBRARIES(queryTest taos query gtest pthread) ENDIF() \ No newline at end of file -- GitLab