diff --git a/source/common/src/cos.c b/source/common/src/cos.c index 6e9c7dd50d..3b5fca0fea 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -1024,7 +1024,7 @@ int32_t s3PutObjectFromFile2(const char *file, const char *object_name, int8_t w } static int32_t s3PutObjectFromFileOffsetByEp(const char *file, const char *object_name, int64_t offset, int64_t size, - int8_t epIndex) { + int8_t epIndex) { int32_t code = 0; int32_t lmtime = 0; const char *filename = 0; @@ -1136,7 +1136,10 @@ static S3Status listBucketCallback(int isTruncated, const char *nextMarker, int const S3ListBucketContent *content = &(contents[i]); // printf("%-50s", content->key); char *object_key = strdup(content->key); - (void)taosArrayPush(data->objectArray, &object_key); + if (!taosArrayPush(data->objectArray, &object_key)) { + taosMemoryFree(object_key); + return S3StatusOutOfMemory; + } } data->keyCount += contentsCount; diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index ae57576279..6d7a77688d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -553,7 +553,7 @@ static int32_t reallocVarDataVal(SValue *pValue) { static int32_t reallocVarData(SColVal *pColVal) { return reallocVarDataVal(&pColVal->value); } // realloc pk data and col data. -static int32_t tsdbCacheReallocSLastCol(SLastCol *pCol, size_t* pCharge) { +static int32_t tsdbCacheReallocSLastCol(SLastCol *pCol, size_t *pCharge) { int32_t code = TSDB_CODE_SUCCESS, lino = 0; size_t charge = sizeof(SLastCol); @@ -587,8 +587,8 @@ _exit: TAOS_RETURN(code); } -void tsdbCacheFreeSLastColItem(void* pItem) { - SLastCol* pCol = (SLastCol*)pItem; +void tsdbCacheFreeSLastColItem(void *pItem) { + SLastCol *pCol = (SLastCol *)pItem; for (int i = 0; i < pCol->rowKey.numOfPKs; i++) { if (IS_VAR_DATA_TYPE(pCol->rowKey.pks[i].type)) { taosMemoryFree(pCol->rowKey.pks[i].pData); @@ -1162,8 +1162,13 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray } else { if (!remainCols) { remainCols = taosArrayInit(num_keys * 2, sizeof(SIdxKey)); + if (!remainCols) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } + } + if (!taosArrayPush(remainCols, &(SIdxKey){i, *key})) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); } - (void)taosArrayPush(remainCols, &(SIdxKey){i, *key}); } } @@ -1309,14 +1314,20 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 int32_t iCol = 0; for (SColVal *pColVal = tsdbRowIterNext(&iter); pColVal && iCol < nCol; pColVal = tsdbRowIterNext(&iter), iCol++) { SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST_ROW, .tsdbRowKey = tsdbRowKey, .colVal = *pColVal}; - (void)taosArrayPush(ctxArray, &updateCtx); + if (!taosArrayPush(ctxArray, &updateCtx)) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } if (!COL_VAL_IS_VALUE(pColVal)) { - (void)tSimpleHashPut(iColHash, &iCol, sizeof(iCol), NULL, 0); + if (!tSimpleHashPut(iColHash, &iCol, sizeof(iCol), NULL, 0)) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } continue; } updateCtx.lflag = LFLAG_LAST; - (void)taosArrayPush(ctxArray, &updateCtx); + if (!taosArrayPush(ctxArray, &updateCtx)) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } } tsdbRowClose(&iter); @@ -1340,7 +1351,9 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 if (COL_VAL_IS_VALUE(&colVal)) { SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST, .tsdbRowKey = tsdbRowKey, .colVal = colVal}; - (void)taosArrayPush(ctxArray, &updateCtx); + if (!taosArrayPush(ctxArray, &updateCtx)) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } (void)tSimpleHashIterateRemove(iColHash, &iCol, sizeof(iCol), &pIte, &iter); } } @@ -1358,7 +1371,7 @@ _exit: } int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlockData *pBlockData) { - int32_t code = 0; + int32_t code = 0, lino = 0; TSDBROW lRow = tsdbRowFromBlockData(pBlockData, pBlockData->nRow - 1); @@ -1380,7 +1393,9 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo .tsdbRowKey = tsdbRowKey, .colVal = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, ((SValue){.type = TSDB_DATA_TYPE_TIMESTAMP, .val = lRow.pBlockData->aTSKEY[lRow.iRow]}))}; - (void)taosArrayPush(ctxArray, &updateCtx); + if (!taosArrayPush(ctxArray, &updateCtx)) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } } TSDBROW tRow = tsdbRowFromBlockData(pBlockData, 0); @@ -1401,7 +1416,9 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo tColDataGetValue(pColData, tRow.iRow, &colVal); SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST, .tsdbRowKey = tsdbRowKey, .colVal = colVal}; - (void)taosArrayPush(ctxArray, &updateCtx); + if (!taosArrayPush(ctxArray, &updateCtx)) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } break; } } @@ -1412,7 +1429,9 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo (void)tsdbRowIterOpen(&iter, &lRow, pTSchema); for (SColVal *pColVal = tsdbRowIterNext(&iter); pColVal; pColVal = tsdbRowIterNext(&iter)) { SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST_ROW, .tsdbRowKey = tsdbRowKey, .colVal = *pColVal}; - (void)taosArrayPush(ctxArray, &updateCtx); + if (!taosArrayPush(ctxArray, &updateCtx)) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } } tsdbRowClose(&iter); @@ -1481,7 +1500,9 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); } } - (void)taosArrayPush(lastTmpIndexArray, &(i)); + if (!taosArrayPush(lastTmpIndexArray, &(i))) { + TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + } lastColIds[lastIndex] = idxKey->key.cid; lastSlotIds[lastIndex] = pr->pSlotIds[idxKey->idx]; lastIndex++; @@ -1492,7 +1513,9 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); } } - (void)taosArrayPush(lastrowTmpIndexArray, &(i)); + if (!taosArrayPush(lastrowTmpIndexArray, &(i))) { + TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + } lastrowColIds[lastrowIndex] = idxKey->key.cid; lastrowSlotIds[lastrowIndex] = pr->pSlotIds[idxKey->idx]; lastrowIndex++; @@ -1819,7 +1842,7 @@ _exit: } int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey) { - int32_t code = 0; + int32_t code = 0, lino = 0; // fetch schema STSchema *pTSchema = NULL; int sver = -1; @@ -1850,7 +1873,9 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE if (!remainCols) { remainCols = taosArrayInit(numCols * 2, sizeof(SLastKey)); } - (void)taosArrayPush(remainCols, &lastKey); + if (!taosArrayPush(remainCols, &lastKey)) { + TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + } } } } @@ -2034,10 +2059,12 @@ static int32_t getTableDelDataFromTbData(STbData *pTbData, SArray *aDelData) { SDelData *pDelData = pTbData ? pTbData->pHead : NULL; for (; pDelData; pDelData = pDelData->pNext) { - (void)taosArrayPush(aDelData, pDelData); + if (!taosArrayPush(aDelData, pDelData)) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } } - return code; + TAOS_RETURN(code); } static void freeTableInfoFunc(void *param) { @@ -2169,7 +2196,9 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea TD_VID(pReader->pTsdb->pVnode), pReader->pCurFileSet->fid, record.skey, record.ekey, uid);*/ SDelData delData = {.version = record.version, .sKey = record.skey, .eKey = record.ekey}; - (void)taosArrayPush(pInfo->pTombData, &delData); + if (!taosArrayPush(pInfo->pTombData, &delData)) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } } } @@ -2387,7 +2416,9 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie SBrinBlk *pBrinBlk = &pBlkArray->data[i]; if (state->suid >= pBrinBlk->minTbid.suid && state->suid <= pBrinBlk->maxTbid.suid) { if (state->uid >= pBrinBlk->minTbid.uid && state->uid <= pBrinBlk->maxTbid.uid) { - (void)taosArrayPush(state->pIndexList, pBrinBlk); + if (!taosArrayPush(state->pIndexList, pBrinBlk)) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _err); + } } } else if (state->suid > pBrinBlk->maxTbid.suid || (state->suid == pBrinBlk->maxTbid.suid && state->uid > pBrinBlk->maxTbid.uid)) { @@ -3004,7 +3035,9 @@ static int32_t initLastColArrayPartial(STSchema *pTSchema, SArray **ppColArray, int16_t slotId = slotIds[i]; SLastCol col = {.rowKey.ts = 0, .colVal = COL_VAL_NULL(pTSchema->columns[slotId].colId, pTSchema->columns[slotId].type)}; - (void)taosArrayPush(pColArray, &col); + if (!taosArrayPush(pColArray, &col)) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } } *ppColArray = pColArray; @@ -3058,7 +3091,11 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC } for (int i = 0; i < nCols; ++i) { - (void)taosArrayPush(aColArray, &aCols[i]); + if (!taosArrayPush(aColArray, &aCols[i])) { + taosArrayDestroy(pColArray); + + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } } STsdbRowKey lastRowKey = {.key.ts = TSKEY_MAX}; @@ -3227,7 +3264,11 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, } for (int i = 0; i < nCols; ++i) { - (void)taosArrayPush(aColArray, &aCols[i]); + if (!taosArrayPush(aColArray, &aCols[i])) { + taosArrayDestroy(pColArray); + + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } } // inverse iterator diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index d0c7dea451..0eb011113a 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -417,7 +417,13 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { SWalFileInfo fileInfo; (void)memset(&fileInfo, -1, sizeof(SWalFileInfo)); (void)sscanf(name, "%" PRId64 ".log", &fileInfo.firstVer); - (void)taosArrayPush(actualLog, &fileInfo); + if (!taosArrayPush(actualLog, &fileInfo)) { + regfree(&logRegPattern); + regfree(&idxRegPattern); + (void)taosCloseDir(&pDir); + + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } } } @@ -730,9 +736,12 @@ int32_t walRollFileInfo(SWal* pWal) { pNewInfo->closeTs = -1; pNewInfo->fileSize = 0; pNewInfo->syncedOffset = 0; - (void)taosArrayPush(pArray, pNewInfo); - taosMemoryFree(pNewInfo); + if (!taosArrayPush(pArray, pNewInfo)) { + taosMemoryFree(pNewInfo); + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } + taosMemoryFree(pNewInfo); TAOS_RETURN(TSDB_CODE_SUCCESS); } diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c index ddcf4aebfa..eaca2f73a4 100644 --- a/source/util/src/tlrucache.c +++ b/source/util/src/tlrucache.c @@ -310,7 +310,9 @@ static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArr TAOS_LRU_ENTRY_SET_IN_CACHE(old, false); shard->usage -= old->totalCharge; - (void)taosArrayPush(deleted, &old); + if (!taosArrayPush(deleted, &old)) { + // ignore this round's eviting + } } } @@ -382,7 +384,11 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry * if (shard->usage + e->totalCharge > shard->capacity && (shard->strictCapacity || handle == NULL)) { TAOS_LRU_ENTRY_SET_IN_CACHE(e, false); if (handle == NULL) { - (void)taosArrayPush(lastReferenceList, &e); + if (!taosArrayPush(lastReferenceList, &e)) { + (void)taosThreadMutexUnlock(&shard->mutex); + taosLRUEntryFree(e); + return status; + } } else { if (freeOnFail) { taosMemoryFree(e); @@ -403,7 +409,11 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry * taosLRUCacheShardLRURemove(shard, old); shard->usage -= old->totalCharge; - (void)taosArrayPush(lastReferenceList, &old); + if (!taosArrayPush(lastReferenceList, &old)) { + (void)taosThreadMutexUnlock(&shard->mutex); + taosLRUEntryFree(old); + return status; + } } } if (handle == NULL) { @@ -519,7 +529,10 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) { TAOS_LRU_ENTRY_SET_IN_CACHE(old, false); shard->usage -= old->totalCharge; - (void)taosArrayPush(lastReferenceList, &old); + if (!taosArrayPush(lastReferenceList, &old)) { + taosLRUEntryFree(old); + return; + } } (void)taosThreadMutexUnlock(&shard->mutex);