From 21754a009cada77b9c8613354249b220677af478 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 27 Jul 2024 18:03:16 +0800 Subject: [PATCH 1/2] enh: add more check return --- include/common/tmsg.h | 9 ++- source/common/src/tdataformat.c | 6 +- source/dnode/vnode/src/meta/metaQuery.c | 30 +++++--- source/dnode/vnode/src/meta/metaTable.c | 14 ++-- source/dnode/vnode/src/tsdb/tsdbFS2.c | 6 +- source/dnode/vnode/src/tsdb/tsdbReadUtil.c | 87 ++++++++++++++-------- source/dnode/vnode/src/vnd/vnodeSvr.c | 41 ++++++++-- source/libs/sync/src/syncRespMgr.c | 4 +- source/libs/tdb/src/db/tdbBtree.c | 15 +--- source/util/src/tarray.c | 2 - source/util/src/tcache.c | 2 +- source/util/src/tlrucache.c | 8 +- 12 files changed, 144 insertions(+), 80 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 4830593616..75a67ea484 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2899,7 +2899,6 @@ static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) { } pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t)); if (pRebInfo->newConsumers == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; goto _err; } return pRebInfo; @@ -3455,7 +3454,9 @@ static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTo buf = taosDecodeStringTo(buf, pTopicInfo->name); int32_t sz; buf = taosDecodeFixedI32(buf, &sz); - pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo)); + if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) { + return NULL; + } for (int32_t i = 0; i < sz; i++) { SMqReportVgInfo vgInfo; buf = taosDecodeSMqVgInfo(buf, &vgInfo); @@ -3493,7 +3494,9 @@ static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) buf = taosDecodeFixedI64(buf, &pMsg->consumerId); int32_t sz; buf = taosDecodeFixedI32(buf, &sz); - pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo)); + if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) { + return NULL; + } for (int32_t i = 0; i < sz; i++) { SMqTopicInfo topicInfo; buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo); diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index dabdc630f5..371fc130f0 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -459,7 +459,7 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, SColVal colVal; if ((colValArray = taosArrayInit(numOfInfos, sizeof(SColVal))) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t iRow = 0; iRow < numOfRows; iRow++) { @@ -670,7 +670,7 @@ static int32_t tRowMergeImpl(SArray *aRowP, STSchema *pTSchema, int32_t iStart, // merge aColVal = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)); if (aColVal == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -1748,7 +1748,7 @@ int32_t tTagToValArray(const STag *pTag, SArray **ppArray) { (*ppArray) = taosArrayInit(pTag->nTag + 1, sizeof(STagVal)); if (*ppArray == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index e4a04047f1..6640f4aa07 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -1070,13 +1070,15 @@ int32_t metaFilterCreateTime(void *pVnode, SMetaFltParam *arg, SArray *pUids) { int32_t cmp = (*param->filterFunc)((void *)&p->btime, (void *)&pBtimeKey->btime, param->type); if (cmp == 0) - taosArrayPush(pUids, &p->uid); - else { - if (param->equal == true) { - if (count > TRY_ERROR_LIMIT) break; - count++; + if (taosArrayPush(pUids, &p->uid) == NULL) { + ret = terrno; + break; + } else { + if (param->equal == true) { + if (count > TRY_ERROR_LIMIT) break; + count++; + } } - } valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur); if (valid < 0) break; } while (1); @@ -1132,7 +1134,10 @@ int32_t metaFilterTableName(void *pVnode, SMetaFltParam *arg, SArray *pUids) { cmp = (*param->filterFunc)(pTableKey, pName, pCursor->type); if (cmp == 0) { tb_uid_t tuid = *(tb_uid_t *)pEntryVal; - taosArrayPush(pUids, &tuid); + if (taosArrayPush(pUids, &tuid) == NULL) { + ret = terrno; + goto END; + } } else { if (param->equal == true) { if (count > TRY_ERROR_LIMIT) break; @@ -1328,7 +1333,10 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) { } else { tuid = *(tb_uid_t *)(p->data + tDataTypes[pCursor->type].bytes); } - taosArrayPush(pUids, &tuid); + if (taosArrayPush(pUids, &tuid) == NULL) { + ret = terrno; + break; + } found = true; } else { if (param->equal == true) { @@ -1432,7 +1440,11 @@ int32_t metaGetTableTags(void *pVnode, uint64_t suid, SArray *pUidTagInfo) { STUidTagInfo info = {.uid = uid, .pTagVal = pCur->pVal}; info.pTagVal = taosMemoryMalloc(pCur->vLen); memcpy(info.pTagVal, pCur->pVal, pCur->vLen); - taosArrayPush(pUidTagInfo, &info); + if (taosArrayPush(pUidTagInfo, &info) == NULL) { + metaCloseCtbCursor(pCur); + taosHashCleanup(pSepecifiedUidMap); + return TSDB_CODE_OUT_OF_MEMORY; + } } } else { // only the specified tables need to be added while (1) { diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 52151e76d6..04447fd3ce 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -341,7 +341,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb break; } - taosArrayPush(tbUidList, &(((SCtbIdxKey *)pKey)->uid)); + (void)taosArrayPush(tbUidList, &(((SCtbIdxKey *)pKey)->uid)); } tdbTbcClose(pCtbIdxc); @@ -405,7 +405,7 @@ static void metaGetSubtables(SMeta *pMeta, int64_t suid, SArray *uids) { break; } - taosArrayPush(uids, &(((SCtbIdxKey *)pKey)->uid)); + (void)taosArrayPush(uids, &(((SCtbIdxKey *)pKey)->uid)); } tdbFree(pKey); @@ -1033,7 +1033,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi } if ((type == TSDB_CHILD_TABLE || type == TSDB_NORMAL_TABLE) && tbUids) { - taosArrayPush(tbUids, &uid); + (void)taosArrayPush(tbUids, &uid); if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { tsdbCacheDropTable(pMeta->pVnode->pTsdb, uid, suid, NULL); @@ -1135,7 +1135,7 @@ static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) { tbFName[TSDB_TABLE_FNAME_LEN] = '\0'; int32_t ret = vnodeValidateTableHash(pMeta->pVnode, tbFName); if (ret < 0 && terrno == TSDB_CODE_VND_HASH_MISMATCH) { - taosArrayPush(uidList, &me.uid); + (void)taosArrayPush(uidList, &me.uid); } } tDecoderClear(&dc); @@ -1783,11 +1783,11 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA } else { memcpy(&val.i64, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal); } - taosArrayPush(pTagArray, &val); + (void)taosArrayPush(pTagArray, &val); } else { STagVal val = {.cid = pCol->colId}; if (tTagGet(pOldTag, &val)) { - taosArrayPush(pTagArray, &val); + (void)taosArrayPush(pTagArray, &val); } } } @@ -2171,7 +2171,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT } SMetaPair pair = {.key = pKey, nKey = nKey}; - taosArrayPush(tagIdxList, &pair); + (void)taosArrayPush(tagIdxList, &pair); } tdbTbcClose(pTagIdxc); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 68954e5156..3b0a40c475 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -770,7 +770,11 @@ int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) { STFileSet *fset; TARRAY2_FOREACH(fs->fSetArr, fset) { if (fset->channelOpened) { - taosArrayPush(channelArray, &fset->channel); + if (taosArrayPush(channelArray, &fset->channel) == NULL) { + taosArrayDestroy(channelArray); + taosThreadMutexUnlock(&pTsdb->mutex); + return terrno; + } fset->channel = (SVAChannelID){0}; fset->mergeScheduled = false; tsdbFSSetBlockCommit(fset, false); diff --git a/source/dnode/vnode/src/tsdb/tsdbReadUtil.c b/source/dnode/vnode/src/tsdb/tsdbReadUtil.c index 64569e63ac..0cb6a152b0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadUtil.c @@ -88,6 +88,9 @@ int32_t ensureBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables) { int32_t remainder = (numOfTables - pBuf->numOfTables) % pBuf->numPerBucket; if (pBuf->pData == NULL) { pBuf->pData = taosArrayInit(num + 1, POINTER_BYTES); + if (pBuf->pData == NULL) { + return terrno; + } } for (int32_t i = 0; i < num; ++i) { @@ -163,22 +166,22 @@ int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, in if (IS_NUMERIC_TYPE(type)) { if (asc) { - switch(type) { + switch (type) { case TSDB_DATA_TYPE_BIGINT: { pKey->pks[0].val = INT64_MIN; break; } - case TSDB_DATA_TYPE_INT:{ + case TSDB_DATA_TYPE_INT: { int32_t min = INT32_MIN; (void)memcpy(&pKey->pks[0].val, &min, tDataTypes[type].bytes); break; } - case TSDB_DATA_TYPE_SMALLINT:{ + case TSDB_DATA_TYPE_SMALLINT: { int16_t min = INT16_MIN; (void)memcpy(&pKey->pks[0].val, &min, tDataTypes[type].bytes); break; } - case TSDB_DATA_TYPE_TINYINT:{ + case TSDB_DATA_TYPE_TINYINT: { int8_t min = INT8_MIN; (void)memcpy(&pKey->pks[0].val, &min, tDataTypes[type].bytes); break; @@ -194,15 +197,31 @@ int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, in ASSERT(0); } } else { - switch(type) { - case TSDB_DATA_TYPE_BIGINT:pKey->pks[0].val = INT64_MAX;break; - case TSDB_DATA_TYPE_INT:pKey->pks[0].val = INT32_MAX;break; - case TSDB_DATA_TYPE_SMALLINT:pKey->pks[0].val = INT16_MAX;break; - case TSDB_DATA_TYPE_TINYINT:pKey->pks[0].val = INT8_MAX;break; - case TSDB_DATA_TYPE_UBIGINT:pKey->pks[0].val = UINT64_MAX;break; - case TSDB_DATA_TYPE_UINT:pKey->pks[0].val = UINT32_MAX;break; - case TSDB_DATA_TYPE_USMALLINT:pKey->pks[0].val = UINT16_MAX;break; - case TSDB_DATA_TYPE_UTINYINT:pKey->pks[0].val = UINT8_MAX;break; + switch (type) { + case TSDB_DATA_TYPE_BIGINT: + pKey->pks[0].val = INT64_MAX; + break; + case TSDB_DATA_TYPE_INT: + pKey->pks[0].val = INT32_MAX; + break; + case TSDB_DATA_TYPE_SMALLINT: + pKey->pks[0].val = INT16_MAX; + break; + case TSDB_DATA_TYPE_TINYINT: + pKey->pks[0].val = INT8_MAX; + break; + case TSDB_DATA_TYPE_UBIGINT: + pKey->pks[0].val = UINT64_MAX; + break; + case TSDB_DATA_TYPE_UINT: + pKey->pks[0].val = UINT32_MAX; + break; + case TSDB_DATA_TYPE_USMALLINT: + pKey->pks[0].val = UINT16_MAX; + break; + case TSDB_DATA_TYPE_UTINYINT: + pKey->pks[0].val = UINT8_MAX; + break; default: ASSERT(0); } @@ -232,7 +251,7 @@ void clearRowKey(SRowKey* pKey) { taosMemoryFreeClear(pKey->pks[0].pData); } -static int32_t initLastProcKey(STableBlockScanInfo *pScanInfo, STsdbReader* pReader) { +static int32_t initLastProcKey(STableBlockScanInfo* pScanInfo, STsdbReader* pReader) { int32_t code = 0; int32_t numOfPks = pReader->suppInfo.numOfPks; bool asc = ASCENDING_TRAVERSE(pReader->info.order); @@ -448,8 +467,8 @@ void cleanupInfoForNextFileset(SSHashObj* pTableMap) { // brin records iterator void initBrinRecordIter(SBrinRecordIter* pIter, SDataFileReader* pReader, SArray* pList) { - (void) memset(&pIter->block, 0, sizeof(SBrinBlock)); - (void) memset(&pIter->record, 0, sizeof(SBrinRecord)); + (void)memset(&pIter->block, 0, sizeof(SBrinBlock)); + (void)memset(&pIter->record, 0, sizeof(SBrinRecord)); pIter->blockIndex = -1; pIter->recordIndex = -1; @@ -471,7 +490,7 @@ int32_t getNextBrinRecord(SBrinRecordIter* pIter, SBrinRecord** pRecord) { return TSDB_CODE_INVALID_PARA; } - (void) tBrinBlockClear(&pIter->block); + (void)tBrinBlockClear(&pIter->block); int32_t code = tsdbDataFileReadBrinBlock(pIter->pReader, pIter->pCurrentBlk, &pIter->block); if (code != TSDB_CODE_SUCCESS) { tsdbError("failed to read brinBlock from file, code:%s", tstrerror(code)); @@ -488,7 +507,7 @@ int32_t getNextBrinRecord(SBrinRecordIter* pIter, SBrinRecord** pRecord) { return code; } -void clearBrinBlockIter(SBrinRecordIter* pIter) { (void) tBrinBlockDestroy(&pIter->block); } +void clearBrinBlockIter(SBrinRecordIter* pIter) { (void)tBrinBlockDestroy(&pIter->block); } // initialize the file block access order // sort the file blocks according to the offset of each data block in the files @@ -658,7 +677,7 @@ int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int3 STableBlockScanInfo* pTableScanInfo = taosArrayGetP(pTableList, 0); for (int32_t i = 0; i < numOfBlocks; ++i) { STableDataBlockIdx tableDataBlockIdx = {.globalIndex = i}; - void* px = taosArrayPush(pTableScanInfo->pBlockIdxList, &tableDataBlockIdx); + void* px = taosArrayPush(pTableScanInfo->pBlockIdxList, &tableDataBlockIdx); if (px == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -774,6 +793,9 @@ static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_ if (pScanInfo->pFileDelData == NULL) { pScanInfo->pFileDelData = taosArrayInit(4, sizeof(SDelData)); + if (pScanInfo->pFileDelData == NULL) { + return terrno; + } } for (int32_t k = 0; k < pBlock->numOfRecords; ++k) { @@ -810,6 +832,9 @@ static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_ if (pScanInfo->pFileDelData == NULL) { pScanInfo->pFileDelData = taosArrayInit(4, sizeof(SDelData)); + if (pScanInfo->pFileDelData == NULL) { + return terrno; + } } } @@ -821,7 +846,7 @@ static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_ if (record.version <= pReader->info.verRange.maxVer) { SDelData delData = {.version = record.version, .sKey = record.skey, .eKey = record.ekey}; - void* px = taosArrayPush(pScanInfo->pFileDelData, &delData); + void* px = taosArrayPush(pScanInfo->pFileDelData, &delData); if (px == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -878,7 +903,7 @@ static int32_t doLoadTombDataFromTombBlk(const TTombBlkArray* pTombBlkArray, STs ETombBlkCheckEnum ret = 0; code = doCheckTombBlock(&block, pReader, numOfTables, &j, &ret); - (void) tTombBlockDestroy(&block); + (void)tTombBlockDestroy(&block); if (code != TSDB_CODE_SUCCESS || ret == BLK_CHECK_QUIT) { return code; } @@ -977,7 +1002,7 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo SStatisBlk* p = &pStatisBlkArray->data[i]; STbStatisBlock* pStatisBlock = taosMemoryCalloc(1, sizeof(STbStatisBlock)); - (void) tStatisBlockInit(pStatisBlock); + (void)tStatisBlockInit(pStatisBlock); int64_t st = taosGetTimestampMs(); int32_t code = tsdbSttFileReadStatisBlock(pSttFileReader, p, pStatisBlock); @@ -995,7 +1020,7 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo } if (index >= pStatisBlock->numOfRecords) { - (void) tStatisBlockDestroy(pStatisBlock); + (void)tStatisBlockDestroy(pStatisBlock); taosMemoryFreeClear(pStatisBlock); return num; } @@ -1005,7 +1030,7 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo while (i < TARRAY2_SIZE(pStatisBlkArray) && uidIndex < numOfTables) { p = &pStatisBlkArray->data[i]; if (p->minTbid.suid > suid) { - (void) tStatisBlockDestroy(pStatisBlock); + (void)tStatisBlockDestroy(pStatisBlock); taosMemoryFreeClear(pStatisBlock); return num; } @@ -1025,7 +1050,7 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo } } - (void) tStatisBlockDestroy(pStatisBlock); + (void)tStatisBlockDestroy(pStatisBlock); taosMemoryFreeClear(pStatisBlock); return num; } @@ -1037,7 +1062,7 @@ static void loadNextStatisticsBlock(SSttFileReader* pSttFileReader, STbStatisBlo (*i) += 1; (*j) = 0; if ((*i) < TARRAY2_SIZE(pStatisBlkArray)) { - (void) tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[(*i)], pStatisBlock); + (void)tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[(*i)], pStatisBlock); } } } @@ -1049,7 +1074,7 @@ int32_t doAdjustValidDataIters(SArray* pLDIterList, int32_t numOfFileObj) { int32_t inc = numOfFileObj - size; for (int32_t k = 0; k < inc; ++k) { SLDataIter* pIter = taosMemoryCalloc(1, sizeof(SLDataIter)); - void* px = taosArrayPush(pLDIterList, &pIter); + void* px = taosArrayPush(pLDIterList, &pIter); if (px == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1073,6 +1098,9 @@ int32_t adjustSttDataIters(SArray* pSttFileBlockIterArray, STFileSet* pFileSet) // add the list/iter placeholder while (taosArrayGetSize(pSttFileBlockIterArray) < numOfLevels) { SArray* pList = taosArrayInit(4, POINTER_BYTES); + if (pList == NULL) { + return terrno; + } void* px = taosArrayPush(pSttFileBlockIterArray, &pList); if (px == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -1210,8 +1238,7 @@ static int32_t sortUidComparFn(const void* p1, const void* p2) { return ret; } -bool isCleanSttBlock(SArray* pKeyRangeList, STimeWindow* pQueryWindow, STableBlockScanInfo* pScanInfo, - int32_t order) { +bool isCleanSttBlock(SArray* pKeyRangeList, STimeWindow* pQueryWindow, STableBlockScanInfo* pScanInfo, int32_t order) { // check if it overlap with del skyline taosArraySort(pKeyRangeList, sortUidComparFn); @@ -1242,7 +1269,7 @@ bool isCleanSttBlock(SArray* pKeyRangeList, STimeWindow* pQueryWindow, STableBlo } STimeWindow w2 = {.skey = p2->skey.ts, .ekey = p2->ekey.ts}; - bool overlap = overlapWithTimeWindow(&w2, pQueryWindow, pScanInfo, order); + bool overlap = overlapWithTimeWindow(&w2, pQueryWindow, pScanInfo, order); if (overlap) { return false; } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 45b2abeb24..1b656442a5 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -1124,7 +1124,11 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, sprintf(tbName, "%s.%s", pVnode->config.dbname, pCreateReq->name); if (vnodeValidateTableHash(pVnode, tbName) < 0) { cRsp.code = TSDB_CODE_VND_HASH_MISMATCH; - taosArrayPush(rsp.pArray, &cRsp); + if (taosArrayPush(rsp.pArray, &cRsp) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + rcode = -1; + goto _exit; + } vError("vgId:%d create-table:%s failed due to hash value mismatch", TD_VID(pVnode), tbName); continue; } @@ -1139,11 +1143,19 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, } else { cRsp.code = TSDB_CODE_SUCCESS; tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid); - taosArrayPush(tbUids, &pCreateReq->uid); + if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + rcode = -1; + goto _exit; + } vnodeUpdateMetaRsp(pVnode, cRsp.pMeta); } - taosArrayPush(rsp.pArray, &cRsp); + if (taosArrayPush(rsp.pArray, &cRsp) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + rcode = -1; + goto _exit; + } } vDebug("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids)); @@ -1375,12 +1387,20 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in if (tbUid > 0) tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid); } - taosArrayPush(rsp.pArray, &dropTbRsp); + if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + pRsp->code = terrno; + goto _exit; + } if (tsEnableAuditCreateTable) { char *str = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN); strcpy(str, pDropTbReq->name); - taosArrayPush(tbNames, &str); + if (taosArrayPush(tbNames, &str) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + pRsp->code = terrno; + goto _exit; + } } } @@ -1499,11 +1519,13 @@ static int32_t vnodeResetTableCxt(SMeta *pMeta, SSubmitReqConvertCxt *pCxt) { taosArrayDestroy(pCxt->pColValues); pCxt->pColValues = taosArrayInit(pCxt->pTbSchema->numOfCols, sizeof(SColVal)); if (NULL == pCxt->pColValues) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < pCxt->pTbSchema->numOfCols; ++i) { SColVal val = COL_VAL_NONE(pCxt->pTbSchema->columns[i].colId, pCxt->pTbSchema->columns[i].type); - taosArrayPush(pCxt->pColValues, &val); + if (taosArrayPush(pCxt->pColValues, &val) == NULL) { + return terrno; + } } return TSDB_CODE_SUCCESS; @@ -1819,7 +1841,10 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, in goto _exit; } - taosArrayPush(newTbUids, &pSubmitTbData->uid); + if (taosArrayPush(newTbUids, &pSubmitTbData->uid) == NULL) { + code = terrno; + goto _exit; + } if (pCreateTbRsp->pMeta) { vnodeUpdateMetaRsp(pVnode, pCreateTbRsp->pMeta); diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index 4663a1f6e9..aa7a6da0a2 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -142,7 +142,9 @@ static int32_t syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { int64_t nowMS = taosGetTimestampMs(); if (nowMS - pStub->createTime > ttl || -1 == ttl) { - taosArrayPush(delIndexArray, pSeqNum); + if (taosArrayPush(delIndexArray, pSeqNum) == NULL) { + return terrno; + } cnt++; SFsmCbMeta cbMeta = { diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 187d65d975..f86ed69fc3 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1366,11 +1366,6 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, if (ret < 0) { return ret; } - /* - if (pDecoder->ofps) { - taosArrayPush(pDecoder->ofps, &ofp); - } - */ ofpCell = tdbPageGetCell(ofp, 0); if (nLeft <= ofp->maxLocal - sizeof(SPgno)) { @@ -1411,11 +1406,6 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, if (ret < 0) { return ret; } - /* - if (pDecoder->ofps) { - taosArrayPush(pDecoder->ofps, &ofp); - } - */ ofpCell = tdbPageGetCell(ofp, 0); int lastKeyPage = 0; @@ -1642,7 +1632,10 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN * SArray *ofps = pPage->pPager->ofps; if (ofps) { - taosArrayPush(ofps, &ofp); + if (taosArrayPush(ofps, &ofp) == NULL) { + ASSERT(0); + return terrno; + } } tdbPagerReturnPage(pPage->pPager, ofp, pTxn); diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c index 49132037d4..660b757bb2 100644 --- a/source/util/src/tarray.c +++ b/source/util/src/tarray.c @@ -34,14 +34,12 @@ SArray* taosArrayInit(size_t size, size_t elemSize) { SArray* pArray = taosMemoryMalloc(sizeof(SArray)); if (pArray == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } pArray->size = 0; pArray->pData = taosMemoryCalloc(size, elemSize); if (pArray->pData == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(pArray); return NULL; } diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c index c0ed0b98d0..17b985b5e0 100644 --- a/source/util/src/tcache.c +++ b/source/util/src/tcache.c @@ -169,7 +169,7 @@ TdThread doRegisterCacheObj(SCacheObj *pCacheObj) { taosThreadOnce(&cacheThreadInit, doInitRefreshThread); taosThreadMutexLock(&guard); - taosArrayPush(pCacheArrayList, &pCacheObj); + (void)taosArrayPush(pCacheArrayList, &pCacheObj); taosThreadMutexUnlock(&guard); return cacheRefreshWorker; diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c index 7e165a12d5..e08dc009fc 100644 --- a/source/util/src/tlrucache.c +++ b/source/util/src/tlrucache.c @@ -326,7 +326,7 @@ static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArr ASSERT(shard->usage >= old->totalCharge); shard->usage -= old->totalCharge; - taosArrayPush(deleted, &old); + (void)taosArrayPush(deleted, &old); } } @@ -392,7 +392,7 @@ 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) { - taosArrayPush(lastReferenceList, &e); + (void)taosArrayPush(lastReferenceList, &e); } else { if (freeOnFail) { taosMemoryFree(e); @@ -415,7 +415,7 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry * ASSERT(shard->usage >= old->totalCharge); shard->usage -= old->totalCharge; - taosArrayPush(lastReferenceList, &old); + (void)taosArrayPush(lastReferenceList, &old); } } if (handle == NULL) { @@ -536,7 +536,7 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) { ASSERT(shard->usage >= old->totalCharge); shard->usage -= old->totalCharge; - taosArrayPush(lastReferenceList, &old); + (void)taosArrayPush(lastReferenceList, &old); } (void)taosThreadMutexUnlock(&shard->mutex); From ea4065d36b06b3094fb139428eb2fda465c9dc46 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 27 Jul 2024 20:09:29 +0800 Subject: [PATCH 2/2] fix possible error --- source/dnode/vnode/src/meta/metaQuery.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 6640f4aa07..ee616d7a0d 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -1069,16 +1069,17 @@ int32_t metaFilterCreateTime(void *pVnode, SMetaFltParam *arg, SArray *pUids) { if (count > TRY_ERROR_LIMIT) break; int32_t cmp = (*param->filterFunc)((void *)&p->btime, (void *)&pBtimeKey->btime, param->type); - if (cmp == 0) + if (cmp == 0) { if (taosArrayPush(pUids, &p->uid) == NULL) { ret = terrno; break; - } else { - if (param->equal == true) { - if (count > TRY_ERROR_LIMIT) break; - count++; - } } + } else { + if (param->equal == true) { + if (count > TRY_ERROR_LIMIT) break; + count++; + } + } valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur); if (valid < 0) break; } while (1);