From 2d9e2f01ba0411f2a7ef25ab0c3bea4f71da493c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 10 Jun 2022 11:20:11 +0800 Subject: [PATCH] fix: avoid invalid read/write --- source/libs/transport/src/transCli.c | 12 ++++++------ source/libs/transport/src/transSvr.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e62a73b7fa..d1debc6af6 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1097,15 +1097,16 @@ void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransM if (index == -1) { index = cliRBChoseIdx(pTransInst); } + tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t)); + tsem_init(sem, 0, 0); STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); pCtx->epSet = *pEpSet; pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; pCtx->hThrdIdx = index; - pCtx->pSem = taosMemoryCalloc(1, sizeof(tsem_t)); + pCtx->pSem = sem; pCtx->pRsp = pRsp; - tsem_init(pCtx->pSem, 0, 0); SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); cliMsg->ctx = pCtx; @@ -1118,10 +1119,9 @@ void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransM EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); transSendAsync(thrd->asyncPool, &(cliMsg->q)); - tsem_t* pSem = pCtx->pSem; - tsem_wait(pSem); - tsem_destroy(pSem); - taosMemoryFree(pSem); + tsem_wait(sem); + tsem_destroy(sem); + taosMemoryFree(sem); } /* diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index cfd711e6eb..4c4714e248 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -226,7 +226,7 @@ static bool addHandleToAcceptloop(void* arg); } else { \ refId = exh1->refId; \ } \ - } else if (refId == -1) { \ + } else if (refId < 0) { \ tTrace("server handle step3"); \ goto _return2; \ } \ -- GitLab