Merge pull request #28061 from taosdata/fix/fixMemLeak30

fix possible mem leak
This commit is contained in:
Hongze Cheng 2024-09-25 08:51:37 +08:00 committed by GitHub
commit 13a50eb010
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 7 deletions

View File

@ -1634,7 +1634,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;
} }
@ -1646,7 +1646,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) {
@ -3316,13 +3316,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;
} }
@ -3336,7 +3337,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);
} }
@ -3349,11 +3350,19 @@ 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);
if (code != 0) {
if (transpointId != 0) {
(void)transReleaseExHandle(transGetRefMgt(), transpointId);
(void)transRemoveExHandle(transGetRefMgt(), transpointId);
}
taosMemoryFree(pCli);
}
return code; return code;
} }

View File

@ -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);
} }