From 68ca5f522557380ff1f0e02252c8e5d6443d15ee Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 7 Aug 2020 14:11:47 +0800 Subject: [PATCH] [td-225]fix memory leaks. --- src/query/src/qTsbuf.c | 1 + src/query/tests/CMakeLists.txt | 2 +- src/query/tests/tsBufTest.cpp | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index fe39fe4e4a..95581e1869 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -72,6 +72,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { // invalid file if (header.magic != TS_COMP_FILE_MAGIC) { + tsBufDestroy(pTSBuf); return NULL; } diff --git a/src/query/tests/CMakeLists.txt b/src/query/tests/CMakeLists.txt index 1856223391..bd7dcd4b89 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 ./tsBufTest.cpp) TARGET_LINK_LIBRARIES(queryTest taos query gtest pthread gcov) ENDIF() diff --git a/src/query/tests/tsBufTest.cpp b/src/query/tests/tsBufTest.cpp index 28b1d9cefe..f8738eec9c 100644 --- a/src/query/tests/tsBufTest.cpp +++ b/src/query/tests/tsBufTest.cpp @@ -47,6 +47,8 @@ void simpleTest() { EXPECT_EQ(pTSBuf->block.numOfElem, num); tsBufDestroy(pTSBuf); + + free(list); } // one large list of ts, the ts list need to be split into several small blocks @@ -71,6 +73,7 @@ void largeTSTest() { EXPECT_EQ(pTSBuf->block.numOfElem, num); tsBufDestroy(pTSBuf); + free(list); } void multiTagsTest() { @@ -208,6 +211,8 @@ void loadDataTest() { int64_t e = taosGetTimestampUs(); printf("end:%" PRIu64 ", elapsed:%" PRIu64 ", total obj:%d\n", e, e - s, x); + tsBufDestroy(pTSBuf); + tsBufDestroy(pNewBuf); } void randomIncTsTest() {} @@ -338,6 +343,8 @@ void TSTraverse() { } } } + + tsBufDestroy(pTSBuf); } void performanceTest() {} @@ -352,9 +359,12 @@ void invalidFileTest() { STSBuf* pNewBuf = tsBufCreateFromFile("/tmp/test", true); EXPECT_TRUE(pNewBuf == NULL); + tsBufDestroy(pNewBuf); pNewBuf = tsBufCreateFromFile("/tmp/911", true); EXPECT_TRUE(pNewBuf == NULL); + + tsBufDestroy(pNewBuf); } void mergeDiffVnodeBufferTest() { -- GitLab