Merge pull request #28143 from taosdata/fix/3.0/TD-32356

fix dbcache obj use after free
This commit is contained in:
Pan Wei 2024-09-27 14:57:59 +08:00 committed by GitHub
commit a7094c07f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -1583,7 +1583,7 @@ int32_t ctgDropTSMAForTbEnqueue(SCatalog *pCtg, SName *pName, bool syncOp) {
SCtgTSMACache *pCtgCache = NULL;
(void)tNameGetFullDbName(pName, dbFName);
CTG_ERR_JRET(ctgGetDBCache(pCtg, dbFName, &pDbCache));
CTG_ERR_JRET(ctgAcquireDBCache(pCtg, dbFName, &pDbCache));
if (NULL == pDbCache || !pDbCache->tsmaCache) {
goto _return;
}
@ -1613,6 +1613,7 @@ int32_t ctgDropTSMAForTbEnqueue(SCatalog *pCtg, SName *pName, bool syncOp) {
CTG_ERR_JRET(ctgEnqueue(pCtg, pOp));
taosHashRelease(pDbCache->tsmaCache, pCtgCache);
ctgReleaseDBCache(pCtg, pDbCache);
return TSDB_CODE_SUCCESS;
@ -1621,6 +1622,9 @@ _return:
if (pCtgCache) {
taosHashRelease(pDbCache->tsmaCache, pCtgCache);
}
if (pDbCache) {
ctgReleaseDBCache(pCtg, pDbCache);
}
if (pOp) {
taosMemoryFree(pOp->data);
taosMemoryFree(pOp);
@ -3996,17 +4000,20 @@ int32_t ctgGetTbTSMAFromCache(SCatalog* pCtg, SCtgTbTSMACtx* pCtx, int32_t dbIdx
if (pCache->retryFetch || hasOutOfDateTSMACache(pCache->pTsmas)) {
CTG_UNLOCK(CTG_READ, &pCache->tsmaLock);
taosHashRelease(dbCache->tsmaCache, pCache);
ctgDebug("tsma for tb: %s.%s not in cache", tsmaSourceTbName.tname, dbFName);
CTG_ERR_JRET(ctgAddTSMAFetch(&pCtx->pFetches, dbIdx, i, fetchIdx, baseResIdx + i, flag, FETCH_TB_TSMA, &tsmaSourceTbName));
if (NULL == taosArrayPush(pCtx->pResList, &(SMetaRes){0})) {
taosHashRelease(dbCache->tsmaCache, pCache);
CTG_ERR_JRET(terrno);
}
CTG_CACHE_NHIT_INC(CTG_CI_TBL_TSMA, 1);
CTG_LOCK(CTG_WRITE, &pCache->tsmaLock);
pCache->retryFetch = false;
CTG_UNLOCK(CTG_WRITE, &pCache->tsmaLock);
taosHashRelease(dbCache->tsmaCache, pCache);
continue;
}