From 6addac61f8b48cf503a40649bfd10e049c4c7f56 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 1 Aug 2022 09:58:49 +0800 Subject: [PATCH 1/2] fix: fix client memory leak --- source/client/src/clientEnv.c | 1 + source/libs/catalog/src/ctgUtil.c | 10 +++++++++- source/libs/nodes/src/nodesUtilFuncs.c | 1 + source/libs/parser/src/parTranslater.c | 1 + source/libs/scheduler/src/schRemote.c | 23 +++++++++++++++-------- source/libs/scheduler/src/schTask.c | 7 ++++++- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 3d539ea251..95ce5c8338 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -316,6 +316,7 @@ void doDestroyRequest(void *p) { taosArrayDestroy(pRequest->tableList); taosArrayDestroy(pRequest->dbList); + taosArrayDestroy(pRequest->targetTableList); destroyQueryExecRes(&pRequest->body.resInfo.execRes); diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index e61becbe17..bdf60b110b 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -30,12 +30,20 @@ void ctgFreeMsgSendParam(void* param) { taosMemoryFree(param); } +void ctgFreeBatchMsg(void* msg) { + if (NULL == msg) { + return; + } + SBatchMsg* pMsg = (SBatchMsg*)msg; + taosMemoryFree(pMsg->msg); +} + void ctgFreeBatch(SCtgBatch *pBatch) { if (NULL == pBatch) { return; } - taosArrayDestroy(pBatch->pMsgs); + taosArrayDestroyEx(pBatch->pMsgs, ctgFreeBatchMsg); taosArrayDestroy(pBatch->pTaskIds); } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 37d80917b3..abab2126c0 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -745,6 +745,7 @@ void nodesDestroyNode(SNode* pNode) { } taosArrayDestroy(pQuery->pDbList); taosArrayDestroy(pQuery->pTableList); + taosArrayDestroy(pQuery->pTargetTableList); taosArrayDestroy(pQuery->pPlaceholderValues); nodesDestroyNode(pQuery->pPrepareRoot); break; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 02a7ca0fbb..5d1889194e 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -398,6 +398,7 @@ static void destroyTranslateContext(STranslateContext* pCxt) { taosHashCleanup(pCxt->pDbs); taosHashCleanup(pCxt->pTables); + taosHashCleanup(pCxt->pTargetTables); } static bool isSelectStmt(SNode* pCurrStmt) { diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 3bec91226c..544ecce175 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -92,7 +92,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa switch (msgType) { case TDMT_VND_COMMIT_RSP: { SCH_ERR_JRET(rspCode); - SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } case TDMT_VND_CREATE_TABLE_RSP: { @@ -118,7 +118,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_JRET(rspCode); taosMemoryFreeClear(msg); - SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } case TDMT_VND_DROP_TABLE_RSP: { @@ -144,7 +144,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_JRET(rspCode); taosMemoryFreeClear(msg); - SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } case TDMT_VND_ALTER_TABLE_RSP: { @@ -169,7 +169,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa taosMemoryFreeClear(msg); - SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } case TDMT_VND_SUBMIT_RSP: { @@ -218,7 +218,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa taosMemoryFreeClear(msg); - SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -238,7 +238,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa taosMemoryFreeClear(msg); - SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -263,7 +263,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa taosMemoryFreeClear(msg); - SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -379,13 +379,15 @@ int32_t schHandleCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { qDebug("begin to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, tstrerror(rspCode)); - SCH_ERR_RET(schProcessOnCbBegin(&pJob, &pTask, pParam->queryId, pParam->refId, pParam->taskId)); + SCH_ERR_JRET(schProcessOnCbBegin(&pJob, &pTask, pParam->queryId, pParam->refId, pParam->taskId)); code = schHandleResponseMsg(pJob, pTask, pParam->execId, pMsg, rspCode); pMsg->pData = NULL; schProcessOnCbEnd(pJob, pTask, code); +_return: + taosMemoryFreeClear(pMsg->pData); qDebug("end to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, @@ -398,6 +400,9 @@ int32_t schHandleDropCallback(void *param, SDataBuf *pMsg, int32_t code) { SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " drop task rsp received, code:0x%x", pParam->queryId, pParam->taskId, code); + if (pMsg) { + taosMemoryFree(pMsg->pData); + } return TSDB_CODE_SUCCESS; } @@ -408,6 +413,8 @@ int32_t schHandleLinkBrokenCallback(void *param, SDataBuf *pMsg, int32_t code) { qDebug("handle %p is broken", pMsg->handle); if (head->isHbParam) { + taosMemoryFree(pMsg->pData); + SSchHbCallbackParam *hbParam = (SSchHbCallbackParam *)param; SSchTrans trans = {.pTrans = hbParam->pTrans, .pHandle = NULL}; SCH_ERR_RET(schUpdateHbConnection(&hbParam->nodeEpId, &trans)); diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index 025891a26c..ecd0253e1c 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -424,10 +424,15 @@ int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf *pData, int32 } } - SCH_RET(schDoTaskRedirect(pJob, pTask, pData, rspCode)); + code = schDoTaskRedirect(pJob, pTask, pData, rspCode); + taosMemoryFree(pData->pData); + + SCH_RET(code); _return: + taosMemoryFree(pData->pData); + SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); } From 27437d852751ff1040910a69cc5878a9474e3624 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Aug 2022 10:44:02 +0800 Subject: [PATCH 2/2] test: valgrind case --- tests/script/tsim/valgrind/basic2.sim | 52 ++++----------------------- 1 file changed, 7 insertions(+), 45 deletions(-) diff --git a/tests/script/tsim/valgrind/basic2.sim b/tests/script/tsim/valgrind/basic2.sim index 7c905209ee..522070f487 100644 --- a/tests/script/tsim/valgrind/basic2.sim +++ b/tests/script/tsim/valgrind/basic2.sim @@ -1,7 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c debugflag -v 131 -system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode1 -s start -v sql connect print =============== step1: create drop show dnodes @@ -42,53 +41,16 @@ while $i < $tbNum sql insert into $tb values ($ms , $x , $x , $x ) $x = $x + 1 endw - - $cc = $x * 60000 - $ms = 1601481600000 + $cc - sql insert into $tb values ($ms , NULL , NULL , NULL ) $i = $i + 1 endw -system sh/exec.sh -n dnode1 -s stop -x SIGINT -system sh/exec.sh -n dnode1 -s start -v - print =============== step3: tb -sql select avg(tbcol) from tb1 -sql select avg(tbcol) from tb1 where ts <= 1601481840000 -sql select avg(tbcol) as b from tb1 -sql select avg(tbcol) as b from tb1 interval(1d) -sql select avg(tbcol) as b from tb1 where ts <= 1601481840000 interval(1m) -sql select bottom(tbcol, 2) from tb1 where ts <= 1601481840000 -sql select top(tbcol, 2) from tb1 where ts <= 1601481840000 -sql select percentile(tbcol, 2) from tb1 where ts <= 1601481840000 -sql select leastsquares(tbcol, 1, 1) as b from tb1 where ts <= 1601481840000 -sql show table distributed tb1 -sql select count(tbcol) as b from tb1 where ts <= 1601481840000 interval(1m) -sql select diff(tbcol) from tb1 where ts <= 1601481840000 -sql select diff(tbcol) from tb1 where tbcol > 5 and tbcol < 20 -sql select first(tbcol), last(tbcol) as b from tb1 where ts <= 1601481840000 interval(1m) -sql select count(tbcol), avg(tbcol), max(tbcol), min(tbcol), sum(tbcol), stddev(tbcol) from tb1 where ts <= 1601481840000 partition by tgcol interval(1m) -#sql select count(tbcol), avg(tbcol), max(tbcol), min(tbcol), count(tbcol) from tb1 where ts <= 1601481840000 and ts >= 1601481800000 partition by tgcol interval(1m) fill(value, 0) -sql select last_row(*) from tb1 where tbcol > 5 and tbcol < 20 - -print =============== step4: stb -sql select avg(tbcol) as c from stb -sql select avg(tbcol) as c from stb where ts <= 1601481840000 -sql select avg(tbcol) as c from stb where tgcol < 5 and ts <= 1601481840000 -sql select avg(tbcol) as c from stb interval(1m) -sql select avg(tbcol) as c from stb interval(1d) -sql select avg(tbcol) as b from stb where ts <= 1601481840000 interval(1m) -sql select avg(tbcol) as c from stb group by tgcol -sql select avg(tbcol) as b from stb where ts <= 1601481840000 partition by tgcol interval(1m) -sql show table distributed stb -sql select count(tbcol) as b from stb where ts <= 1601481840000 partition by tgcol interval(1m) -sql select diff(tbcol) from stb where ts <= 1601481840000 -sql select first(tbcol), last(tbcol) as c from stb group by tgcol -sql select first(tbcol), last(tbcol) as b from stb where ts <= 1601481840000 and tbcol2 is null partition by tgcol interval(1m) -sql select first(tbcol), last(tbcol) as b from stb where ts <= 1601481840000 partition by tgcol interval(1m) -sql select count(tbcol), avg(tbcol), max(tbcol), min(tbcol), sum(tbcol), stddev(tbcol) from stb where ts <= 1601481840000 partition by tgcol interval(1m) -#sql select count(tbcol), avg(tbcol), max(tbcol), min(tbcol), count(tbcol) from stb where ts <= 1601481840000 and ts >= 1601481800000 partition by tgcol interval(1m) fill(value, 0) -sql select last_row(tbcol), stddev(tbcol) from stb where tbcol > 5 and tbcol < 20 group by tgcol +sql select * from tb1 where ts in ('2018-07-10 16:31:01', '2022-07-10 16:31:03', 1657441865000); +sql select * from tb1 where tbcol2 in (257); +sql select * from tb1 where tbcol3 in (2, 257); +sql select * from stb where ts in ('2018-07-10 16:31:01', '2022-07-10 16:31:03', 1657441865000); +sql select * from stb where tbcol2 in (257); +sql select * from stb where tbcol3 in (2, 257); _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT