From 9f0315a98fa45521749262836581584c61f19224 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 27 May 2022 16:05:24 +0800 Subject: [PATCH 1/2] fix: avoid mem leak when taosd quit --- source/libs/transport/inc/transComm.h | 15 +++++++++++++++ source/libs/transport/src/transCli.c | 1 + source/libs/transport/src/transComm.c | 1 + source/libs/transport/src/transSrv.c | 1 + 4 files changed, 18 insertions(+) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 91a721d80f..f8b3893782 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -217,6 +217,21 @@ SAsyncPool* transCreateAsyncPool(uv_loop_t* loop, int sz, void* arg, AsyncCB cb) void transDestroyAsyncPool(SAsyncPool* pool); int transSendAsync(SAsyncPool* pool, queue* mq); +#define TRANS_DESTROY_ASYNC_POOL_MSG(pool, msgType, freeFunc) \ + do { \ + for (int i = 0; i < pool->nAsync; i++) { \ + uv_async_t* async = &(pool->asyncs[i]); \ + SAsyncItem* item = async->data; \ + while (!QUEUE_IS_EMPTY(&item->qmsg)) { \ + queue* h = QUEUE_HEAD(&item->qmsg); \ + QUEUE_REMOVE(h); \ + msgType* msg = QUEUE_DATA(h, msgType, q); \ + if (msg != NULL) { \ + freeFunc(msg); \ + } \ + } \ + } \ + } while (0) int transInitBuffer(SConnBuffer* buf); int transClearBuffer(SConnBuffer* buf); int transDestroyBuffer(SConnBuffer* buf); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f0af0d99c9..3220e229a6 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -892,6 +892,7 @@ static void destroyThrdObj(SCliThrdObj* pThrd) { taosThreadJoin(pThrd->thread, NULL); CLI_RELEASE_UV(pThrd->loop); taosThreadMutexDestroy(&pThrd->msgMtx); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliMsg, destroyCmsg); transDestroyAsyncPool(pThrd->asyncPool); transDQDestroy(pThrd->delayQueue); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 526f896ad2..be07fbd264 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -190,6 +190,7 @@ SAsyncPool* transCreateAsyncPool(uv_loop_t* loop, int sz, void* arg, AsyncCB cb) } return pool; } + void transDestroyAsyncPool(SAsyncPool* pool) { for (int i = 0; i < pool->nAsync; i++) { uv_async_t* async = &(pool->asyncs[i]); diff --git a/source/libs/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index 12cfff093c..9018eaacf6 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -1036,6 +1036,7 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) { } taosThreadJoin(pThrd->thread, NULL); SRV_RELEASE_UV(pThrd->loop); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSrvMsg, destroySmsg); transDestroyAsyncPool(pThrd->asyncPool); taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd); From 79e447dad1e1ae888d42524ef3d8fc9a7b2033a3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 27 May 2022 16:13:42 +0800 Subject: [PATCH 2/2] fix: avoid mem leak when taosd quit --- source/libs/transport/inc/transComm.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index f8b3893782..5ba6c4029e 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -223,6 +223,7 @@ int transSendAsync(SAsyncPool* pool, queue* mq); uv_async_t* async = &(pool->asyncs[i]); \ SAsyncItem* item = async->data; \ while (!QUEUE_IS_EMPTY(&item->qmsg)) { \ + tTrace("destroy msg in async pool "); \ queue* h = QUEUE_HEAD(&item->qmsg); \ QUEUE_REMOVE(h); \ msgType* msg = QUEUE_DATA(h, msgType, q); \