Merge pull request #5117 from taosdata/hotfix/TD-2885-2

[TD-2885]fix memleak issue
This commit is contained in:
haojun Liao 2021-02-03 17:59:58 +08:00 committed by GitHub
commit 6f8ec9d856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 20 deletions

View File

@ -91,6 +91,20 @@ void cqRmFromList(SCqObj *pObj) {
} }
static void freeSCqContext(void *handle) {
if (handle == NULL) {
return;
}
SCqContext *pContext = handle;
pthread_mutex_destroy(&pContext->mutex);
taosTmrCleanUp(pContext->tmrCtrl);
pContext->tmrCtrl = NULL;
cDebug("vgId:%d, CQ is closed", pContext->vgId);
free(pContext);
}
void cqFree(void *handle) { void cqFree(void *handle) {
if (tsEnableStream == 0) { if (tsEnableStream == 0) {
return; return;
@ -125,13 +139,7 @@ void cqFree(void *handle) {
pthread_mutex_unlock(&pContext->mutex); pthread_mutex_unlock(&pContext->mutex);
if (delete) { if (delete) {
pthread_mutex_destroy(&pContext->mutex); freeSCqContext(pContext);
taosTmrCleanUp(pContext->tmrCtrl);
pContext->tmrCtrl = NULL;
cDebug("vgId:%d, CQ is closed", pContext->vgId);
free(pContext);
} }
} }
@ -184,18 +192,7 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) {
return pContext; return pContext;
} }
static void freeSCqContext(void *handle) {
if (handle == NULL) {
return;
}
SCqContext *pContext = handle;
pthread_mutex_destroy(&pContext->mutex);
taosTmrCleanUp(pContext->tmrCtrl);
pContext->tmrCtrl = NULL;
cDebug("vgId:%d, CQ is closed", pContext->vgId);
free(pContext);
}
void cqClose(void *handle) { void cqClose(void *handle) {
if (tsEnableStream == 0) { if (tsEnableStream == 0) {
return; return;
@ -204,6 +201,8 @@ void cqClose(void *handle) {
if (handle == NULL) return; if (handle == NULL) return;
pContext->delete = 1; pContext->delete = 1;
int32_t hasCq = 0;
int32_t existLoop = 0;
// stop all CQs // stop all CQs
cqStop(pContext); cqStop(pContext);
@ -218,6 +217,12 @@ void cqClose(void *handle) {
cqRmFromList(pObj); cqRmFromList(pObj);
rid = pObj->rid; rid = pObj->rid;
hasCq = 1;
if (pContext->pHead == NULL) {
existLoop = 1;
}
} else { } else {
pthread_mutex_unlock(&pContext->mutex); pthread_mutex_unlock(&pContext->mutex);
break; break;
@ -226,9 +231,15 @@ void cqClose(void *handle) {
pthread_mutex_unlock(&pContext->mutex); pthread_mutex_unlock(&pContext->mutex);
taosRemoveRef(cqObjRef, rid); taosRemoveRef(cqObjRef, rid);
if (existLoop) {
break;
}
} }
if (hasCq == 0) {
freeSCqContext(pContext); freeSCqContext(pContext);
}
} }
void cqStart(void *handle) { void cqStart(void *handle) {