From 5843d1e86ebfd67c7491a5e22fb3ef48f6f2a758 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 25 May 2023 18:09:32 +0800 Subject: [PATCH 1/4] fix: add free query --- src/benchTmq.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/benchTmq.c b/src/benchTmq.c index 77af2fc9..f93e2fe4 100644 --- a/src/benchTmq.c +++ b/src/benchTmq.c @@ -78,6 +78,7 @@ static int create_topic() { } infoPrint("successfully create topic: %s\n", pConsumerInfo->topicName[i]); + taos_free_result(res); } closeBenchConn(conn); return 0; From be372d91e66bb96eec63c3ccfb558a5d7db0a3fa Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Tue, 30 May 2023 17:36:22 +0800 Subject: [PATCH 2/4] test: repair 4 memory leak free res --- src/benchQuery.c | 2 ++ src/benchTmq.c | 1 + 2 files changed, 3 insertions(+) diff --git a/src/benchQuery.c b/src/benchQuery.c index 63816b81..d90eace5 100644 --- a/src/benchQuery.c +++ b/src/benchQuery.c @@ -43,6 +43,7 @@ int selectAndGetResult(threadInfo *pThreadInfo, char *command) { TAOS_RES *res = taos_query(taos, command); int code = taos_errno(res); if (res == NULL || code) { + taos_free_result(res); if (YES_IF_FAILED == g_arguments->continueIfFail) { warnPrint("failed to execute sql:%s, " "code: 0x%08x, reason:%s\n", @@ -112,6 +113,7 @@ static void *mixedQuery(void *sarg) { TAOS_RES *res = taos_query(pThreadInfo->conn->taos, sql->command); if (res == NULL || taos_errno(res) != 0) { + taos_free_result(res); if (YES_IF_FAILED == g_arguments->continueIfFail) { warnPrint( "thread[%d]: failed to execute sql :%s, " diff --git a/src/benchTmq.c b/src/benchTmq.c index f93e2fe4..34b33653 100644 --- a/src/benchTmq.c +++ b/src/benchTmq.c @@ -74,6 +74,7 @@ static int create_topic() { errorPrint("failed to create topic: %s, reason: %s\n", pConsumerInfo->topicName[i], taos_errstr(res)); closeBenchConn(conn); + taos_free_result(res); return -1; } From 1014f0d9ad44363d2319406bc577e67bda996eeb Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Tue, 30 May 2023 17:40:25 +0800 Subject: [PATCH 3/4] fix: first call free beofore close conn --- src/benchTmq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/benchTmq.c b/src/benchTmq.c index 34b33653..4de47719 100644 --- a/src/benchTmq.c +++ b/src/benchTmq.c @@ -73,8 +73,8 @@ static int create_topic() { if (taos_errno(res) != 0) { errorPrint("failed to create topic: %s, reason: %s\n", pConsumerInfo->topicName[i], taos_errstr(res)); - closeBenchConn(conn); taos_free_result(res); + closeBenchConn(conn); return -1; } From 55f62de3ff9ed3e88a92ab55f93c5b1b4e68bc6e Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 31 May 2023 09:15:17 +0800 Subject: [PATCH 4/4] fix: call taos_free_result after reference finished --- src/benchQuery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/benchQuery.c b/src/benchQuery.c index d90eace5..0acb6ecb 100644 --- a/src/benchQuery.c +++ b/src/benchQuery.c @@ -43,7 +43,6 @@ int selectAndGetResult(threadInfo *pThreadInfo, char *command) { TAOS_RES *res = taos_query(taos, command); int code = taos_errno(res); if (res == NULL || code) { - taos_free_result(res); if (YES_IF_FAILED == g_arguments->continueIfFail) { warnPrint("failed to execute sql:%s, " "code: 0x%08x, reason:%s\n", @@ -113,7 +112,6 @@ static void *mixedQuery(void *sarg) { TAOS_RES *res = taos_query(pThreadInfo->conn->taos, sql->command); if (res == NULL || taos_errno(res) != 0) { - taos_free_result(res); if (YES_IF_FAILED == g_arguments->continueIfFail) { warnPrint( "thread[%d]: failed to execute sql :%s, " @@ -130,9 +128,11 @@ static void *mixedQuery(void *sarg) { taos_errno(res), taos_errstr(res)); if (TSDB_CODE_RPC_NETWORK_UNAVAIL == taos_errno(res)) { + taos_free_result(res); return NULL; } } + taos_free_result(res); continue; } taos_free_result(res);