From f32a17c72b86d6b090f2cef92723177c12ce4c1c Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Tue, 27 Aug 2024 11:54:41 +0800 Subject: [PATCH] Modify error code passing for taosMemoryCalloc function --- source/client/src/clientEnv.c | 4 +- source/client/src/clientHb.c | 7 ++-- source/client/src/clientImpl.c | 20 ++++++---- source/client/src/clientMain.c | 8 ++-- source/client/src/clientMsgHandler.c | 6 +-- source/client/src/clientRawBlockWrite.c | 4 +- source/client/src/clientSmlLine.c | 2 +- source/client/src/clientTmq.c | 50 ++++++++++++------------- 8 files changed, 52 insertions(+), 49 deletions(-) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 491a49778c..986927b85d 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -477,7 +477,7 @@ int32_t createTscObj(const char *user, const char *auth, const char *db, int32_t STscObj **pObj) { *pObj = (STscObj *)taosMemoryCalloc(1, sizeof(STscObj)); if (NULL == *pObj) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pObj)->pRequests = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); @@ -556,7 +556,7 @@ int32_t createRequest(uint64_t connId, int32_t type, int64_t reqid, SRequestObj (*pRequest)->inCallback = false; (*pRequest)->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE); if (NULL == (*pRequest)->msgBuf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } (*pRequest)->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 70a519d8ae..9d6f106336 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -169,8 +169,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { int32_t code = 0; SDBVgInfo *vgInfo = taosMemoryCalloc(1, sizeof(SDBVgInfo)); if (NULL == vgInfo) { - code = TSDB_CODE_OUT_OF_MEMORY; - return code; + return terrno; } vgInfo->vgVersion = rsp->vgVersion; @@ -713,7 +712,7 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) { if (NULL == hbBasic) { tscError("calloc %d failed", (int32_t)sizeof(SQueryHbReqBasic)); releaseTscObj(connKey->tscRid); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } hbBasic->connId = pTscObj->connId; @@ -1174,7 +1173,7 @@ static FORCE_INLINE void hbMgrInitHandle() { int32_t hbGatherAllInfo(SAppHbMgr *pAppHbMgr, SClientHbBatchReq **pBatchReq) { *pBatchReq = taosMemoryCalloc(1, sizeof(SClientHbBatchReq)); if (pBatchReq == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t connKeyCnt = atomic_load_32(&pAppHbMgr->connKeyCnt); (*pBatchReq)->reqs = taosArrayInit(connKeyCnt, sizeof(SClientHbReq)); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 039e17fd87..27a66f6df6 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -135,7 +135,7 @@ int32_t taos_connect_internal(const char* ip, const char* user, const char* pass if (pInst == NULL) { p = taosMemoryCalloc(1, sizeof(struct SAppInstInfo)); if (NULL == p) { - TSC_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + TSC_ERR_JRET(terrno); } p->mgmtEp = epSet; code = taosThreadMutexInit(&p->qnodeMutex, NULL); @@ -513,9 +513,11 @@ int32_t setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32 taosMemoryFree(pResInfo->userFields); } pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD)); + if(NULL == pResInfo->fields) return terrno; pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD)); - if (NULL == pResInfo->fields || NULL == pResInfo->userFields) { - return TSDB_CODE_OUT_OF_MEMORY; + if (NULL == pResInfo->userFields) { + taosMemoryFree(pResInfo->fields); + return terrno; } if (numOfCols != pResInfo->numOfCols) { tscError("numOfCols:%d != pResInfo->numOfCols:%d", numOfCols, pResInfo->numOfCols); @@ -1590,7 +1592,7 @@ int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __ta static int32_t buildConnectMsg(SRequestObj* pRequest, SMsgSendInfo** pMsgSendInfo) { *pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (*pMsgSendInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pMsgSendInfo)->msgType = TDMT_MND_CONNECT; @@ -1601,7 +1603,7 @@ static int32_t buildConnectMsg(SRequestObj* pRequest, SMsgSendInfo** pMsgSendInf (*pMsgSendInfo)->param = taosMemoryCalloc(1, sizeof(pRequest->self)); if (NULL == (*pMsgSendInfo)->param) { taosMemoryFree(*pMsgSendInfo); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *(int64_t*)(*pMsgSendInfo)->param = pRequest->self; @@ -1977,7 +1979,11 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { pResInfo->convertBuf = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); if (pResInfo->row == NULL || pResInfo->pCol == NULL || pResInfo->length == NULL || pResInfo->convertBuf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pResInfo->row); + taosMemoryFree(pResInfo->pCol); + taosMemoryFree(pResInfo->length); + taosMemoryFree(pResInfo->convertBuf); + return terrno; } } @@ -2125,7 +2131,7 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int taosMemoryFreeClear(pResultInfo->convertJson); pResultInfo->convertJson = taosMemoryCalloc(1, dataLen); - if (pResultInfo->convertJson == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (pResultInfo->convertJson == NULL) return terrno; char* p1 = pResultInfo->convertJson; int32_t totalLen = 0; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 55401d7eb2..236f1ff739 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -965,7 +965,7 @@ int32_t cloneCatalogReq(SCatalogReq **ppTarget, SCatalogReq *pSrc) { int32_t code = TSDB_CODE_SUCCESS; SCatalogReq *pTarget = taosMemoryCalloc(1, sizeof(SCatalogReq)); if (pTarget == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pTarget->pDbVgroup = taosArrayDup(pSrc->pDbVgroup, NULL); pTarget->pDbCfg = taosArrayDup(pSrc->pDbCfg, NULL); @@ -1174,7 +1174,7 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt, SS *pCxt = taosMemoryCalloc(1, sizeof(SParseContext)); if (*pCxt == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } **pCxt = (SParseContext){.requestId = pRequest->requestId, @@ -1208,7 +1208,7 @@ int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *p STscObj *pTscObj = pRequest->pTscObj; SSqlCallbackWrapper *pWrapper = taosMemoryCalloc(1, sizeof(SSqlCallbackWrapper)); if (pWrapper == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pWrapper->pRequest = pRequest; pRequest->pWrapper = pWrapper; @@ -1229,7 +1229,7 @@ int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *p pWrapper->pCatalogReq = taosMemoryCalloc(1, sizeof(SCatalogReq)); if (pWrapper->pCatalogReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pWrapper->pCatalogReq->forceUpdate = updateMetaForce; TSC_ERR_RET(qnodeRequired(pRequest, &pWrapper->pCatalogReq->qNodeRequired)); diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 771a22b7e3..54020b77ef 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -201,7 +201,7 @@ End: SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) { SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); - + if(pMsgSendInfo == NULL) return pMsgSendInfo; pMsgSendInfo->requestObjRefId = pRequest->self; pMsgSendInfo->requestId = pRequest->requestId; pMsgSendInfo->param = pRequest; @@ -507,7 +507,7 @@ static int32_t buildShowVariablesBlock(SArray* pVars, SSDataBlock** block) { int32_t code = 0; int32_t line = 0; SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - TSDB_CHECK_NULL(pBlock, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pBlock, code, line, END, terrno); pBlock->info.hasVarCol = true; pBlock->pDataBlock = taosArrayInit(SHOW_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData)); @@ -658,7 +658,7 @@ static int32_t buildCompactDbBlock(SCompactDbRsp* pRsp, SSDataBlock** block) { int32_t code = 0; int32_t line = 0; SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - TSDB_CHECK_NULL(pBlock, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pBlock, code, line, END, terrno); pBlock->info.hasVarCol = true; pBlock->pDataBlock = taosArrayInit(COMPACT_DB_RESULT_COLS, sizeof(SColumnInfoData)); diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 7bd2b726e9..d184f8a559 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -1900,7 +1900,7 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen) TAOS_FIELD* fields = taosMemoryCalloc(pSW->nCols, sizeof(TAOS_FIELD)); if (fields == NULL) { SET_ERROR_MSG("calloc fields failed"); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } for (int i = 0; i < pSW->nCols; i++) { @@ -2059,7 +2059,7 @@ static int32_t encodeMqDataRsp(__encode_func__* encodeFunc, void* rspObj, tmq_ra len += sizeof(int8_t) + sizeof(int32_t); buf = taosMemoryCalloc(1, len); if (buf == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto FAILED; } tEncoderInit(&encoder, buf, len); diff --git a/source/client/src/clientSmlLine.c b/source/client/src/clientSmlLine.c index f3efee0805..14a334e54c 100644 --- a/source/client/src/clientSmlLine.c +++ b/source/client/src/clientSmlLine.c @@ -104,7 +104,7 @@ int32_t smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg) { } char* tmp = taosMemoryCalloc(pVal->length, 1); if (tmp == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(tmp, pVal->value + NCHAR_ADD_LEN - 1, pVal->length - NCHAR_ADD_LEN); code = doGeomFromText(tmp, (unsigned char **)&pVal->value, &pVal->length); diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index 1db1df5d2e..5b1462bb5c 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -506,7 +506,7 @@ static int32_t doSendCommitMsg(tmq_t* tmq, int32_t vgId, SEpSet* epSet, STqOffse void* buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)buf)->vgId = htonl(vgId); @@ -526,7 +526,7 @@ static int32_t doSendCommitMsg(tmq_t* tmq, int32_t vgId, SEpSet* epSet, STqOffse SMqCommitCbParam* pParam = taosMemoryCalloc(1, sizeof(SMqCommitCbParam)); if (pParam == NULL) { taosMemoryFree(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pParam->params = pParamSet; @@ -540,7 +540,7 @@ static int32_t doSendCommitMsg(tmq_t* tmq, int32_t vgId, SEpSet* epSet, STqOffse if (pMsgSendInfo == NULL) { taosMemoryFree(buf); taosMemoryFree(pParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pMsgSendInfo->msgInfo = (SDataBuf){.pData = buf, .len = sizeof(SMsgHead) + len, .handle = NULL}; @@ -581,7 +581,7 @@ static int32_t prepareCommitCbParamSet(tmq_t* tmq, tmq_commit_cb* pCommitFp, voi SMqCommitCbParamSet** ppParamSet) { SMqCommitCbParamSet* pParamSet = taosMemoryCalloc(1, sizeof(SMqCommitCbParamSet)); if (pParamSet == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pParamSet->refId = tmq->refId; @@ -1382,7 +1382,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { } char* topicFName = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN); if (topicFName == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto FAIL; } @@ -1414,7 +1414,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (sendInfo == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFree(buf); goto FAIL; } @@ -1842,7 +1842,7 @@ void tmqBuildConsumeReqImpl(SMqPollReq* pReq, tmq_t* tmq, int64_t timeout, SMqCl int32_t tmqBuildMetaRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqMetaRspObj** ppRspObj) { SMqMetaRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqMetaRspObj)); if (pRspObj == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pRspObj->resType = RES_TYPE__TMQ_META; tstrncpy(pRspObj->topic, pWrapper->topicHandle->topicName, TSDB_TOPIC_FNAME_LEN); @@ -1857,7 +1857,7 @@ int32_t tmqBuildMetaRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqMetaRspObj** int32_t tmqBuildBatchMetaRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqBatchMetaRspObj** ppRspObj) { SMqBatchMetaRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqBatchMetaRspObj)); if (pRspObj == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pRspObj->common.resType = RES_TYPE__TMQ_BATCH_META; tstrncpy(pRspObj->common.topic, pWrapper->topicHandle->topicName, TSDB_TOPIC_FNAME_LEN); @@ -1968,7 +1968,7 @@ int32_t tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pVg, in SMqRspObj** ppRspObj) { SMqRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqRspObj)); if (pRspObj == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pRspObj->common.resType = RES_TYPE__TMQ; (void)memcpy(&pRspObj->rsp, &pWrapper->dataRsp, sizeof(SMqDataRsp)); @@ -1981,7 +1981,7 @@ int32_t tmqBuildTaosxRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pV SMqTaosxRspObj** ppRspObj) { SMqTaosxRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqTaosxRspObj)); if (pRspObj == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pRspObj->common.resType = RES_TYPE__TMQ_METADATA; (void)memcpy(&pRspObj->rsp, &pWrapper->taosxRsp, sizeof(STaosxRsp)); @@ -2007,8 +2007,7 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { - code = TSDB_CODE_OUT_OF_MEMORY; - return code; + return terrno; } if (tSerializeSMqPollReq(msg, msgSize, &req) < 0) { @@ -2031,10 +2030,9 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (sendInfo == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFreeClear(pParam); taosMemoryFreeClear(msg); - return code; + return terrno; } sendInfo->msgInfo = (SDataBuf){.pData = msg, .len = msgSize, .handle = NULL}; @@ -2955,7 +2953,7 @@ int32_t askEp(tmq_t* pTmq, void* param, bool sync, bool updateEpSet) { pReq = taosMemoryCalloc(1, tlen); if (pReq == NULL) { tscError("consumer:0x%" PRIx64 ", failed to malloc askEpReq msg, size:%d", pTmq->consumerId, tlen); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (tSerializeSMqAskEpReq(pReq, tlen, &req) < 0) { @@ -2968,7 +2966,7 @@ int32_t askEp(tmq_t* pTmq, void* param, bool sync, bool updateEpSet) { if (pParam == NULL) { tscError("consumer:0x%" PRIx64 ", failed to malloc subscribe param", pTmq->consumerId); taosMemoryFree(pReq); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pParam->refId = pTmq->refId; @@ -2979,7 +2977,7 @@ int32_t askEp(tmq_t* pTmq, void* param, bool sync, bool updateEpSet) { if (sendInfo == NULL) { taosMemoryFree(pReq); taosMemoryFree(pParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sendInfo->msgInfo = (SDataBuf){.pData = pReq, .len = tlen, .handle = NULL}; @@ -3174,7 +3172,7 @@ int64_t getCommittedFromServer(tmq_t* tmq, char* tname, int32_t vgId, SEpSet* ep void* buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)buf)->vgId = htonl(vgId); @@ -3194,14 +3192,14 @@ int64_t getCommittedFromServer(tmq_t* tmq, char* tname, int32_t vgId, SEpSet* ep SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (sendInfo == NULL) { taosMemoryFree(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SMqCommittedParam* pParam = taosMemoryMalloc(sizeof(SMqCommittedParam)); if (pParam == NULL) { taosMemoryFree(buf); taosMemoryFree(sendInfo); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (tsem2_init(&pParam->sem, 0, 0) != 0) { taosMemoryFree(buf); @@ -3392,7 +3390,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a if (*assignment == NULL) { tscError("consumer:0x%" PRIx64 " failed to malloc buffer, size:%" PRIzu, tmq->consumerId, (*numOfAssignment) * sizeof(tmq_topic_assignment)); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } @@ -3420,7 +3418,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a if (needFetch) { pCommon = taosMemoryCalloc(1, sizeof(SMqVgCommon)); if (pCommon == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } @@ -3467,7 +3465,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a char* msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { taosMemoryFree(pParam); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } @@ -3482,7 +3480,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a if (sendInfo == NULL) { taosMemoryFree(pParam); taosMemoryFree(msg); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } @@ -3630,7 +3628,7 @@ int32_t tmq_offset_seek(tmq_t* tmq, const char* pTopicName, int32_t vgId, int64_ char* msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (tSerializeSMqSeekReq(msg, msgSize, &req) < 0) { @@ -3641,7 +3639,7 @@ int32_t tmq_offset_seek(tmq_t* tmq, const char* pTopicName, int32_t vgId, int64_ SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (sendInfo == NULL) { taosMemoryFree(msg); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SMqSeekParam* pParam = taosMemoryMalloc(sizeof(SMqSeekParam));