Merge pull request #27550 from taosdata/fix/TD-31799

fix(lru/insert): free & unlock if alloc failed
This commit is contained in:
Hongze Cheng 2024-08-30 10:21:18 +08:00 committed by GitHub
commit ab71fffb8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 5 deletions

View File

@ -374,6 +374,7 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry *
LRUStatus status = TAOS_LRU_STATUS_OK;
SArray *lastReferenceList = taosArrayInit(16, POINTER_BYTES);
if (!lastReferenceList) {
taosLRUEntryFree(e);
return TAOS_LRU_STATUS_FAIL;
}
@ -385,13 +386,12 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry *
TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
if (handle == NULL) {
if (!taosArrayPush(lastReferenceList, &e)) {
(void)taosThreadMutexUnlock(&shard->mutex);
taosLRUEntryFree(e);
return status;
goto _exit;
}
} else {
if (freeOnFail) {
taosMemoryFree(e);
taosLRUEntryFree(e);
*handle = NULL;
}
@ -410,9 +410,9 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry *
shard->usage -= old->totalCharge;
if (!taosArrayPush(lastReferenceList, &old)) {
(void)taosThreadMutexUnlock(&shard->mutex);
taosLRUEntryFree(e);
taosLRUEntryFree(old);
return status;
goto _exit;
}
}
}
@ -427,6 +427,7 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry *
}
}
_exit:
(void)taosThreadMutexUnlock(&shard->mutex);
for (int i = 0; i < taosArrayGetSize(lastReferenceList); ++i) {