提交 052a6045 编写于 作者: S Shengliang Guan

refcount error for http

上级 61635dc0
...@@ -46,6 +46,8 @@ static void httpDestroyContext(void *data) { ...@@ -46,6 +46,8 @@ static void httpDestroyContext(void *data) {
httpReleaseSession(pContext); httpReleaseSession(pContext);
atomic_sub_fetch_32(&pThread->numOfContexts, 1); atomic_sub_fetch_32(&pThread->numOfContexts, 1);
httpDebug("context:%p, is destroyed, refCount:%d data:%p thread:%s numOfContexts:%d", pContext, pContext->refCount,
data, pContext->pThread->label, pContext->pThread->numOfContexts);
pContext->pThread = 0; pContext->pThread = 0;
pContext->state = HTTP_CONTEXT_STATE_CLOSED; pContext->state = HTTP_CONTEXT_STATE_CLOSED;
...@@ -53,8 +55,6 @@ static void httpDestroyContext(void *data) { ...@@ -53,8 +55,6 @@ static void httpDestroyContext(void *data) {
httpFreeJsonBuf(pContext); httpFreeJsonBuf(pContext);
httpFreeMultiCmds(pContext); httpFreeMultiCmds(pContext);
httpDebug("context:%p, is destroyed, refCount:%d data:%p thread:%s numOfContexts:%d", pContext, pContext->refCount,
data, pContext->pThread->label, pContext->pThread->numOfContexts);
tfree(pContext); tfree(pContext);
} }
...@@ -134,22 +134,16 @@ HttpContext *httpGetContext(void *ptr) { ...@@ -134,22 +134,16 @@ HttpContext *httpGetContext(void *ptr) {
} }
void httpReleaseContext(HttpContext *pContext) { void httpReleaseContext(HttpContext *pContext) {
// Ensure that the context is valid before release int32_t refCount = atomic_sub_fetch_32(&pContext->refCount, 1);
HttpContext **ppContext = taosCacheAcquireByKey(tsHttpServer.contextCache, &pContext, sizeof(HttpContext *)); if (refCount < 0) {
if (ppContext == NULL) { httpError("context:%p, is already released, refCount:%d", pContext, refCount);
httpError("context:%p, is already released", pContext);
return; return;
} }
int32_t refCount = atomic_sub_fetch_32(&pContext->refCount, 1); HttpContext **ppContext = pContext->ppContext;
assert(refCount >= 0);
assert(ppContext == pContext->ppContext);
httpDebug("context:%p, is released, data:%p refCount:%d", pContext, ppContext, refCount); httpDebug("context:%p, is released, data:%p refCount:%d", pContext, ppContext, refCount);
if (tsHttpServer.contextCache != NULL) { if (tsHttpServer.contextCache != NULL) {
// and release context twice
taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false);
taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false); taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false);
} else { } else {
httpDebug("context:%p, won't be destroyed for cache is already released", pContext); httpDebug("context:%p, won't be destroyed for cache is already released", pContext);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册