From c1b3156563520e9a4bdc5c13a230fb0d7f06c28b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 8 Aug 2020 17:48:08 +0800 Subject: [PATCH] [td-225] fix memory leak --- src/client/src/tscSystem.c | 3 ++- src/mnode/src/mnodeDb.c | 2 +- src/mnode/src/mnodeTable.c | 2 +- src/plugins/monitor/src/monitorMain.c | 24 +++++++++++++++++------- src/query/src/qTokenizer.c | 6 +++++- src/util/inc/tstoken.h | 4 ++-- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index a252beec33..2cc237dd83 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -164,7 +164,8 @@ void taos_cleanup() { taosCleanUpScheduler(tscQhandle); tscQhandle = NULL; } - + + taosCleanupKeywordsTable(); taosCloseLog(); taosTmrCleanUp(tscTmr); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 803e44cea2..f6249986fd 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -1046,7 +1046,7 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pDrop->db); if (pMsg->pDb == NULL) { if (pDrop->ignoreNotExists) { - mDebug("db:%s, db is not exist, think drop success", pDrop->db); + mDebug("db:%s, db is not exist, treat as success", pDrop->db); return TSDB_CODE_SUCCESS; } else { mError("db:%s, failed to drop, invalid db", pDrop->db); diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 0912a6f3ff..dbc1bffa5c 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -751,7 +751,7 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pDrop->tableId); if (pMsg->pTable == NULL) { if (pDrop->igNotExists) { - mDebug("app:%p:%p, table:%s, table is not exist, think drop success", pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId); + mDebug("app:%p:%p, table:%s, table is not exist, treat as success", pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId); return TSDB_CODE_SUCCESS; } else { mError("app:%p:%p, table:%s, failed to drop table, table not exist", pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId); diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index 4dc79aef68..644835abc0 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -131,7 +131,10 @@ static void monitorInitConn(void *para, void *unused) { } static void monitorInitConnCb(void *param, TAOS_RES *result, int32_t code) { - if (code < 0) { + // free it firstly in any cases. + taos_free_result(result); + + if (code != TSDB_CODE_SUCCESS) { monitorError("monitor:%p, connect to database failed, reason:%s", tsMonitorConn.conn, tstrerror(code)); taos_close(tsMonitorConn.conn); tsMonitorConn.conn = NULL; @@ -214,7 +217,7 @@ static void monitorInitDatabase() { } static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { - if (-code == TSDB_CODE_MND_TABLE_ALREADY_EXIST || -code == TSDB_CODE_MND_DB_ALREADY_EXIST || code >= 0) { + if (code == TSDB_CODE_MND_TABLE_ALREADY_EXIST || code == TSDB_CODE_MND_DB_ALREADY_EXIST || code >= 0) { monitorDebug("monitor:%p, sql success, reason:%s, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql); if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) { monitorInfo("dnode:%s is started", tsLocalEp); @@ -226,6 +229,8 @@ static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { tsMonitorConn.state = MONITOR_STATE_UN_INIT; monitorStartSystemRetry(); } + + taos_free_result(result); } void monitorStopSystem() { @@ -238,6 +243,8 @@ void monitorStopSystem() { if (tsMonitorConn.timer != NULL) { taosTmrStopA(&(tsMonitorConn.timer)); } + + taos_close(tsMonitorConn.conn); } void monitorCleanUpSystem() { @@ -250,13 +257,16 @@ static void monitorStartTimer() { } static void dnodeMontiorLogCallback(void *param, TAOS_RES *result, int32_t code) { - if (code < 0) { - monitorError("monitor:%p, save %s failed, reason:%s", tsMonitorConn.conn, (char *)param, tstrerror(code)); - } else if (code == 0) { - monitorError("monitor:%p, save %s failed, affect rows:%d", tsMonitorConn.conn, (char *)param, code); + int32_t c = taos_errno(result); + + if (c != TSDB_CODE_SUCCESS) { + monitorError("monitor:%p, save %s failed, reason:%s", tsMonitorConn.conn, (char *)param, tstrerror(c)); } else { - monitorDebug("monitor:%p, save %s info success, reason:%s", tsMonitorConn.conn, (char *)param, tstrerror(code)); + int32_t rows = taos_affected_rows(result); + monitorDebug("monitor:%p, save %s succ, rows:%d", tsMonitorConn.conn, (char *)param, rows); } + + taos_free_result(result); } // unit is MB diff --git a/src/query/src/qTokenizer.c b/src/query/src/qTokenizer.c index 7418bc6895..1fa565ca90 100644 --- a/src/query/src/qTokenizer.c +++ b/src/query/src/qTokenizer.c @@ -25,7 +25,7 @@ // All the keywords of the SQL language are stored in a hash table typedef struct SKeyword { const char* name; // The keyword name - uint16_t type; // type + uint16_t type; // type uint8_t len; // length } SKeyword; @@ -659,3 +659,7 @@ SSQLToken tStrGetToken(char* str, int32_t* i, bool isPrevOptr, uint32_t numOfIgn } bool isKeyWord(const char* z, int32_t len) { return (tSQLKeywordCode((char*)z, len) != TK_ID); } + +void taosCleanupKeywordsTable() { + taosHashCleanup(KeywordHashTable); +} diff --git a/src/util/inc/tstoken.h b/src/util/inc/tstoken.h index 258e62cf8a..c1c6f2de7a 100644 --- a/src/util/inc/tstoken.h +++ b/src/util/inc/tstoken.h @@ -24,8 +24,6 @@ extern "C" { #include "tutil.h" #include "ttokendef.h" - - #define TSQL_TBNAME "TBNAME" #define TSQL_TBNAME_L "tbname" @@ -182,6 +180,8 @@ static FORCE_INLINE int32_t isValidNumber(const SSQLToken* pToken) { return (i < pToken->n)? TK_ILLEGAL:type; } +void taosCleanupKeywordsTable(); + #ifdef __cplusplus } #endif -- GitLab