From fb5db901d70beb5670e309d23a2874586966a5c4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 14 Dec 2021 15:13:10 +0800 Subject: [PATCH] [td-10564] fix memory leak. --- source/client/src/clientImpl.c | 9 +++++++++ source/client/src/tscEnv.c | 1 + 2 files changed, 10 insertions(+) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 47b2c61ffc..2ae79f1947 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -9,6 +9,8 @@ static int32_t initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet); static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody); +static void destroyConnectMsg(SRequestMsgBody* pMsgBody); + static int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId); static bool stringLengthCheck(const char* str, size_t maxsize) { @@ -164,6 +166,8 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId); tsem_wait(&pRequest->body.rspSem); + destroyConnectMsg(&body); + if (pRequest->code != TSDB_CODE_SUCCESS) { const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno); printf("failed to connect to server, reason: %s\n\n", errorMsg); @@ -209,6 +213,11 @@ static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) return 0; } +static void destroyConnectMsg(SRequestMsgBody* pMsgBody) { + assert(pMsgBody != NULL); + tfree(pMsgBody->pData); +} + int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId) { char *pMsg = rpcMallocCont(pBody->msgLen); if (NULL == pMsg) { diff --git a/source/client/src/tscEnv.c b/source/client/src/tscEnv.c index d37eb1ebcb..43d73bf3db 100644 --- a/source/client/src/tscEnv.c +++ b/source/client/src/tscEnv.c @@ -189,6 +189,7 @@ static void doDestroyRequest(void* p) { tfree(pRequest->pInfo); deregisterRequest(pRequest); + tfree(pRequest); } void destroyRequest(SRequestObj* pRequest) {