fix possible mem leak
This commit is contained in:
parent
ba248dd94e
commit
b33fabb2d7
|
@ -493,6 +493,10 @@ void cliHandleResp(SCliConn* conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONN_NO_PERSIST_BY_APP(conn)) {
|
if (CONN_NO_PERSIST_BY_APP(conn)) {
|
||||||
|
if (refId != 0) {
|
||||||
|
(void)transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
|
(void)transRemoveExHandle(transGetRefMgt(), refId);
|
||||||
|
}
|
||||||
return addConnToPool(pThrd->pool, conn);
|
return addConnToPool(pThrd->pool, conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1402,8 +1406,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) {
|
||||||
tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, pList->dst);
|
tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, pList->dst);
|
||||||
int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10);
|
int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn,
|
tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, tstrerror(terrno));
|
||||||
tstrerror(terrno));
|
|
||||||
cliHandleFastFail(conn, -1);
|
cliHandleFastFail(conn, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1636,7 +1639,7 @@ static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
||||||
SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId);
|
SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId);
|
||||||
if (exh == NULL) {
|
if (exh == NULL) {
|
||||||
tDebug("id %" PRId64 " already released", refId);
|
tDebug("refId %" PRId64 " already released", refId);
|
||||||
destroyCmsg(pMsg);
|
destroyCmsg(pMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1648,7 +1651,7 @@ static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
if (conn == NULL || conn->refId != refId) {
|
if (conn == NULL || conn->refId != refId) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception);
|
TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception);
|
||||||
}
|
}
|
||||||
tDebug("do free conn %p by id %" PRId64 "", conn, refId);
|
tDebug("do free conn %p by refId %" PRId64 "", conn, refId);
|
||||||
|
|
||||||
int32_t size = transQueueSize(&conn->cliMsgs);
|
int32_t size = transQueueSize(&conn->cliMsgs);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
|
@ -1882,8 +1885,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
tGTrace("%s conn %p try to connect to %s", pTransInst->label, conn, conn->dstAddr);
|
tGTrace("%s conn %p try to connect to %s", pTransInst->label, conn, conn->dstAddr);
|
||||||
int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10);
|
int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
tGError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn,
|
tGError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, tstrerror(terrno));
|
||||||
tstrerror(terrno));
|
|
||||||
cliHandleExcept(conn, -1);
|
cliHandleExcept(conn, -1);
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -3319,13 +3321,14 @@ int32_t transAllocHandle(int64_t* refId) {
|
||||||
|
|
||||||
QUEUE_INIT(&exh->q);
|
QUEUE_INIT(&exh->q);
|
||||||
taosInitRWLatch(&exh->latch);
|
taosInitRWLatch(&exh->latch);
|
||||||
tDebug("pre alloc refId %" PRId64 "", exh->refId);
|
tDebug("pre alloc refId %" PRId64 ", alloc exhandle %p", exh->refId, exh);
|
||||||
*refId = exh->refId;
|
*refId = exh->refId;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int32_t transFreeConnById(void* shandle, int64_t transpointId) {
|
int32_t transFreeConnById(void* shandle, int64_t transpointId) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle);
|
SCliMsg* pCli = NULL;
|
||||||
|
STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
if (pTransInst == NULL) {
|
if (pTransInst == NULL) {
|
||||||
return TSDB_CODE_RPC_MODULE_QUIT;
|
return TSDB_CODE_RPC_MODULE_QUIT;
|
||||||
}
|
}
|
||||||
|
@ -3339,7 +3342,7 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception);
|
TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCliMsg* pCli = taosMemoryCalloc(1, sizeof(SCliMsg));
|
pCli = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
if (pCli == NULL) {
|
if (pCli == NULL) {
|
||||||
TAOS_CHECK_GOTO(terrno, NULL, _exception);
|
TAOS_CHECK_GOTO(terrno, NULL, _exception);
|
||||||
}
|
}
|
||||||
|
@ -3352,11 +3355,13 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) {
|
||||||
|
|
||||||
code = transAsyncSend(pThrd->asyncPool, &pCli->q);
|
code = transAsyncSend(pThrd->asyncPool, &pCli->q);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
taosMemoryFree(pCli);
|
taosMemoryFreeClear(pCli);
|
||||||
TAOS_CHECK_GOTO(code, NULL, _exception);
|
TAOS_CHECK_GOTO(code, NULL, _exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
_exception:
|
_exception:
|
||||||
transReleaseExHandle(transGetInstMgt(), (int64_t)shandle);
|
transReleaseExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
|
taosMemoryFree(pCli);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -768,6 +768,7 @@ void transDestroyExHandle(void* handle) {
|
||||||
if (!QUEUE_IS_EMPTY(&eh->q)) {
|
if (!QUEUE_IS_EMPTY(&eh->q)) {
|
||||||
tDebug("handle %p mem leak", handle);
|
tDebug("handle %p mem leak", handle);
|
||||||
}
|
}
|
||||||
|
tDebug("free exhandle %p", handle);
|
||||||
taosMemoryFree(handle);
|
taosMemoryFree(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue