From c90ec0d712b0c71fbc9e6cc7281d7f3fc7a3f666 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Wed, 28 Oct 2020 15:04:21 +0000 Subject: [PATCH] link list bug --- src/rpc/src/rpcMain.c | 7 ++++++- src/util/src/tref.c | 13 +++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 294e204791..4c9493bc10 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -215,6 +215,11 @@ static void rpcUnlockConn(SRpcConn *pConn); static void rpcAddRef(SRpcInfo *pRpc); static void rpcDecRef(SRpcInfo *pRpc); +static void rpcFree(void *p) { + tTrace("free mem: %p", p); + free(p); +} + static void rpcInit(void) { tsProgressTimer = tsRpcTimer/2; @@ -222,7 +227,7 @@ static void rpcInit(void) { tsRpcHeadSize = RPC_MSG_OVERHEAD; tsRpcOverhead = sizeof(SRpcReqContext); - tsRpcRefId = taosOpenRef(200, free); + tsRpcRefId = taosOpenRef(200, rpcFree); } void *rpcOpen(const SRpcInit *pInit) { diff --git a/src/util/src/tref.c b/src/util/src/tref.c index 5e0a85fdb6..4c3b836340 100644 --- a/src/util/src/tref.c +++ b/src/util/src/tref.c @@ -159,8 +159,8 @@ int taosAddRef(int refId, void *p) taosLockList(pSet->lockedBy+hash); pNode = pSet->nodeList[hash]; - while ( pNode ) { - if ( pNode->p == p ) + while (pNode) { + if (pNode->p == p) break; pNode = pNode->next; @@ -176,8 +176,9 @@ int taosAddRef(int refId, void *p) pNode->count = 1; pNode->prev = 0; pNode->next = pSet->nodeList[hash]; + if (pSet->nodeList[hash]) pSet->nodeList[hash]->prev = pNode; pSet->nodeList[hash] = pNode; - uTrace("refId:%d p:%p is added, count::%d", refId, p, pSet->count); + uTrace("refId:%d p:%p is added, count:%d malloc mem: %p", refId, p, pSet->count, pNode); } else { code = TSDB_CODE_REF_NO_MEMORY; uTrace("refId:%d p:%p is not added, since no memory", refId, p); @@ -197,7 +198,7 @@ int taosAcquireRef(int refId, void *p) SRefNode *pNode; SRefSet *pSet; - if ( refId < 0 || refId >= TSDB_REF_OBJECTS ) { + if (refId < 0 || refId >= TSDB_REF_OBJECTS) { uTrace("refId:%d p:%p failed to acquire, refId not valid", refId, p); return TSDB_CODE_REF_INVALID_ID; } @@ -267,7 +268,7 @@ void taosReleaseRef(int refId, void *p) pNode = pSet->nodeList[hash]; while (pNode) { - if ( pNode->p == p ) + if (pNode->p == p) break; pNode = pNode->next; @@ -291,7 +292,7 @@ void taosReleaseRef(int refId, void *p) free(pNode); released = 1; - uTrace("refId:%d p:%p is removed, count::%d", refId, p, pSet->count); + uTrace("refId:%d p:%p is removed, count:%d, free mem: %p", refId, p, pSet->count, pNode); } else { uTrace("refId:%d p:%p is released", refId, p); } -- GitLab