提交 16ac4b66 编写于 作者: H Haojun Liao

[td-225] fix memory leak

上级 0836c2f7
...@@ -164,7 +164,8 @@ void taos_cleanup() { ...@@ -164,7 +164,8 @@ void taos_cleanup() {
taosCleanUpScheduler(tscQhandle); taosCleanUpScheduler(tscQhandle);
tscQhandle = NULL; tscQhandle = NULL;
} }
taosCleanupKeywordsTable();
taosCloseLog(); taosCloseLog();
taosTmrCleanUp(tscTmr); taosTmrCleanUp(tscTmr);
......
...@@ -131,7 +131,10 @@ static void monitorInitConn(void *para, void *unused) { ...@@ -131,7 +131,10 @@ static void monitorInitConn(void *para, void *unused) {
} }
static void monitorInitConnCb(void *param, TAOS_RES *result, int32_t code) { 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)); monitorError("monitor:%p, connect to database failed, reason:%s", tsMonitorConn.conn, tstrerror(code));
taos_close(tsMonitorConn.conn); taos_close(tsMonitorConn.conn);
tsMonitorConn.conn = NULL; tsMonitorConn.conn = NULL;
...@@ -214,7 +217,7 @@ static void monitorInitDatabase() { ...@@ -214,7 +217,7 @@ static void monitorInitDatabase() {
} }
static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { 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); monitorDebug("monitor:%p, sql success, reason:%s, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql);
if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) { if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) {
monitorInfo("dnode:%s is started", tsLocalEp); monitorInfo("dnode:%s is started", tsLocalEp);
...@@ -226,6 +229,8 @@ static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { ...@@ -226,6 +229,8 @@ static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) {
tsMonitorConn.state = MONITOR_STATE_UN_INIT; tsMonitorConn.state = MONITOR_STATE_UN_INIT;
monitorStartSystemRetry(); monitorStartSystemRetry();
} }
taos_free_result(result);
} }
void monitorStopSystem() { void monitorStopSystem() {
...@@ -238,6 +243,8 @@ void monitorStopSystem() { ...@@ -238,6 +243,8 @@ void monitorStopSystem() {
if (tsMonitorConn.timer != NULL) { if (tsMonitorConn.timer != NULL) {
taosTmrStopA(&(tsMonitorConn.timer)); taosTmrStopA(&(tsMonitorConn.timer));
} }
taos_close(tsMonitorConn.conn);
} }
void monitorCleanUpSystem() { void monitorCleanUpSystem() {
...@@ -250,13 +257,16 @@ static void monitorStartTimer() { ...@@ -250,13 +257,16 @@ static void monitorStartTimer() {
} }
static void dnodeMontiorLogCallback(void *param, TAOS_RES *result, int32_t code) { static void dnodeMontiorLogCallback(void *param, TAOS_RES *result, int32_t code) {
if (code < 0) { int32_t c = taos_errno(result);
monitorError("monitor:%p, save %s failed, reason:%s", tsMonitorConn.conn, (char *)param, tstrerror(code));
} else if (code == 0) { if (c != TSDB_CODE_SUCCESS) {
monitorError("monitor:%p, save %s failed, affect rows:%d", tsMonitorConn.conn, (char *)param, code); monitorError("monitor:%p, save %s failed, reason:%s", tsMonitorConn.conn, (char *)param, tstrerror(c));
} else { } 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 // unit is MB
......
...@@ -659,3 +659,7 @@ SSQLToken tStrGetToken(char* str, int32_t* i, bool isPrevOptr, uint32_t numOfIgn ...@@ -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); } bool isKeyWord(const char* z, int32_t len) { return (tSQLKeywordCode((char*)z, len) != TK_ID); }
void taosCleanupKeywordsTable() {
taosHashCleanup(KeywordHashTable);
}
\ No newline at end of file
...@@ -182,6 +182,8 @@ static FORCE_INLINE int32_t isValidNumber(const SSQLToken* pToken) { ...@@ -182,6 +182,8 @@ static FORCE_INLINE int32_t isValidNumber(const SSQLToken* pToken) {
return (i < pToken->n)? TK_ILLEGAL:type; return (i < pToken->n)? TK_ILLEGAL:type;
} }
void taosCleanupKeywordsTable();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册