fix: (last) tsdbCacheGetBatch memleak issue

This commit is contained in:
Shungang Li 2024-10-10 16:30:13 +08:00
parent 1440c708b1
commit 9f644cd2b2
1 changed files with 12 additions and 2 deletions

View File

@ -1767,10 +1767,14 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache
SLastCol *pLastCol = h ? (SLastCol *)taosLRUCacheValue(pCache, h) : NULL; SLastCol *pLastCol = h ? (SLastCol *)taosLRUCacheValue(pCache, h) : NULL;
if (h && pLastCol->cacheStatus != TSDB_LAST_CACHE_NO_CACHE) { if (h && pLastCol->cacheStatus != TSDB_LAST_CACHE_NO_CACHE) {
SLastCol lastCol = *pLastCol; SLastCol lastCol = *pLastCol;
TAOS_CHECK_GOTO(tsdbCacheReallocSLastCol(&lastCol, NULL), NULL, _exit); if (TSDB_CODE_SUCCESS != (code = tsdbCacheReallocSLastCol(&lastCol, NULL))) {
tsdbLRUCacheRelease(pCache, h, false);
TAOS_CHECK_GOTO(code, NULL, _exit);
}
if (taosArrayPush(pLastArray, &lastCol) == NULL) { if (taosArrayPush(pLastArray, &lastCol) == NULL) {
code = terrno; code = terrno;
tsdbLRUCacheRelease(pCache, h, false);
goto _exit; goto _exit;
} }
} else { } else {
@ -1780,28 +1784,33 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache
if (taosArrayPush(pLastArray, &noneCol) == NULL) { if (taosArrayPush(pLastArray, &noneCol) == NULL) {
code = terrno; code = terrno;
tsdbLRUCacheRelease(pCache, h, false);
goto _exit; goto _exit;
} }
if (!remainCols) { if (!remainCols) {
if ((remainCols = taosArrayInit(numKeys, sizeof(SIdxKey))) == NULL) { if ((remainCols = taosArrayInit(numKeys, sizeof(SIdxKey))) == NULL) {
code = terrno; code = terrno;
tsdbLRUCacheRelease(pCache, h, false);
goto _exit; goto _exit;
} }
} }
if (!ignoreFromRocks) { if (!ignoreFromRocks) {
if ((ignoreFromRocks = taosArrayInit(numKeys, sizeof(bool))) == NULL) { if ((ignoreFromRocks = taosArrayInit(numKeys, sizeof(bool))) == NULL) {
code = terrno; code = terrno;
tsdbLRUCacheRelease(pCache, h, false);
goto _exit; goto _exit;
} }
} }
if (taosArrayPush(remainCols, &(SIdxKey){i, key}) == NULL) { if (taosArrayPush(remainCols, &(SIdxKey){i, key}) == NULL) {
code = terrno; code = terrno;
tsdbLRUCacheRelease(pCache, h, false);
goto _exit; goto _exit;
} }
bool ignoreRocks = pLastCol ? (pLastCol->cacheStatus == TSDB_LAST_CACHE_NO_CACHE) : false; bool ignoreRocks = pLastCol ? (pLastCol->cacheStatus == TSDB_LAST_CACHE_NO_CACHE) : false;
if (taosArrayPush(ignoreFromRocks, &ignoreRocks) == NULL) { if (taosArrayPush(ignoreFromRocks, &ignoreRocks) == NULL) {
code = terrno; code = terrno;
tsdbLRUCacheRelease(pCache, h, false);
goto _exit; goto _exit;
} }
} }
@ -1822,6 +1831,7 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache
SLastCol lastCol = *pLastCol; SLastCol lastCol = *pLastCol;
code = tsdbCacheReallocSLastCol(&lastCol, NULL); code = tsdbCacheReallocSLastCol(&lastCol, NULL);
if (code) { if (code) {
tsdbLRUCacheRelease(pCache, h, false);
(void)taosThreadMutexUnlock(&pTsdb->lruMutex); (void)taosThreadMutexUnlock(&pTsdb->lruMutex);
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -3600,4 +3610,4 @@ void tsdbCacheSetPageS3(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, uint8_t *
(void)taosThreadMutexUnlock(&pFD->pTsdb->pgMutex); (void)taosThreadMutexUnlock(&pFD->pTsdb->pgMutex);
tsdbCacheRelease(pFD->pTsdb->pgCache, handle); tsdbCacheRelease(pFD->pTsdb->pgCache, handle);
} }