From 69587b3c29dd66163ff491bfd2422c2a606a7272 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 2 Apr 2021 13:45:55 +0800 Subject: [PATCH] [td-225]fix memory leaks. --- src/client/inc/tsclient.h | 1 + src/client/src/tscParseInsert.c | 3 ++- src/client/src/tscUtil.c | 25 +++++++++++++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index e55abdd2dd..4869f65645 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -440,6 +440,7 @@ void tscRestoreFuncForSTableQuery(SQueryInfo *pQueryInfo); int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo); void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo); +void destroyTableNameList(SSqlCmd* pCmd); void tscResetSqlCmd(SSqlCmd *pCmd, bool removeMeta); diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index f5fee0b622..6f74101164 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1420,7 +1420,8 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; STableComInfo tinfo = tscGetTableInfo(pTableMeta); - tfree(pCmd->pTableNameList); + destroyTableNameList(pCmd); + pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); if (pCmd->pTableBlockHashList == NULL) { diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 51ebdaccb8..386352bdc7 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -415,6 +415,20 @@ void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeMeta) { tfree(pCmd->pQueryInfo); } +void destroyTableNameList(SSqlCmd* pCmd) { + if (pCmd->numOfTables == 0) { + assert(pCmd->pTableNameList == NULL); + return; + } + + for(int32_t i = 0; i < pCmd->numOfTables; ++i) { + tfree(pCmd->pTableNameList[i]); + } + + pCmd->numOfTables = 0; + tfree(pCmd->pTableNameList); +} + void tscResetSqlCmd(SSqlCmd* pCmd, bool removeMeta) { pCmd->command = 0; pCmd->numOfCols = 0; @@ -424,14 +438,7 @@ void tscResetSqlCmd(SSqlCmd* pCmd, bool removeMeta) { pCmd->parseFinished = 0; pCmd->autoCreated = 0; - for(int32_t i = 0; i < pCmd->numOfTables; ++i) { - if (pCmd->pTableNameList && pCmd->pTableNameList[i]) { - tfree(pCmd->pTableNameList[i]); - } - } - - pCmd->numOfTables = 0; - tfree(pCmd->pTableNameList); + destroyTableNameList(pCmd); pCmd->pTableBlockHashList = tscDestroyBlockHashTable(pCmd->pTableBlockHashList, removeMeta); pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); @@ -840,6 +847,8 @@ static void extractTableNameList(SSqlCmd* pCmd, bool freeBlockMap) { int32_t i = 0; while(p1) { STableDataBlocks* pBlocks = *p1; + tfree(pCmd->pTableNameList[i]); + pCmd->pTableNameList[i++] = tNameDup(&pBlocks->tableName); p1 = taosHashIterate(pCmd->pTableBlockHashList, p1); } -- GitLab