enh:[TD-32128] Haneld return value of memory alloc functions.
This commit is contained in:
parent
e43c013c36
commit
de16ac5faa
|
@ -552,6 +552,9 @@ int32_t createRequest(uint64_t connId, int32_t type, int64_t reqid, SRequestObj
|
|||
(*pRequest)->allocatorRefId = -1;
|
||||
|
||||
(*pRequest)->pDb = getDbOfConnection(pTscObj);
|
||||
if (NULL == (*pRequest)->pDb) {
|
||||
TSC_ERR_JRET(terrno);
|
||||
}
|
||||
(*pRequest)->pTscObj = pTscObj;
|
||||
(*pRequest)->inCallback = false;
|
||||
(*pRequest)->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
|
|
|
@ -1359,6 +1359,14 @@ static void *hbThreadFunc(void *param) {
|
|||
pInfo->msgInfo.len = tlen;
|
||||
pInfo->msgType = TDMT_MND_HEARTBEAT;
|
||||
pInfo->param = taosMemoryMalloc(sizeof(int32_t));
|
||||
if (pInfo->param == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tFreeClientHbBatchReq(pReq);
|
||||
// hbClearReqInfo(pAppHbMgr);
|
||||
taosMemoryFree(buf);
|
||||
taosMemoryFree(pInfo);
|
||||
break;
|
||||
}
|
||||
*(int32_t *)pInfo->param = i;
|
||||
pInfo->paramFreeFp = taosMemoryFree;
|
||||
pInfo->requestId = generateRequestId();
|
||||
|
|
|
@ -1586,6 +1586,8 @@ int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __ta
|
|||
pRequest->sqlstr = taosStrdup("taos_connect");
|
||||
if (pRequest->sqlstr) {
|
||||
pRequest->sqlLen = strlen(pRequest->sqlstr);
|
||||
} else {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
SMsgSendInfo* body = NULL;
|
||||
|
@ -1649,6 +1651,9 @@ static int32_t buildConnectMsg(SRequestObj* pRequest, SMsgSendInfo** pMsgSendInf
|
|||
char* db = getDbOfConnection(pObj);
|
||||
if (db != NULL) {
|
||||
tstrncpy(connectReq.db, db, sizeof(connectReq.db));
|
||||
} else if (terrno) {
|
||||
taosMemoryFree(*pMsgSendInfo);
|
||||
return terrno;
|
||||
}
|
||||
taosMemoryFreeClear(db);
|
||||
|
||||
|
@ -2396,11 +2401,16 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
|
|||
}
|
||||
|
||||
char* getDbOfConnection(STscObj* pObj) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
char* p = NULL;
|
||||
(void)taosThreadMutexLock(&pObj->mutex);
|
||||
size_t len = strlen(pObj->db);
|
||||
if (len > 0) {
|
||||
p = strndup(pObj->db, tListLen(pObj->db));
|
||||
if (p == NULL) {
|
||||
tscError("failed to strndup db name");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
(void)taosThreadMutexUnlock(&pObj->mutex);
|
||||
|
|
|
@ -4828,6 +4828,9 @@ int32_t histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResul
|
|||
pInfo->normalized = 0;
|
||||
|
||||
char* binTypeStr = strndup(varDataVal(pCtx->param[1].param.pz), varDataLen(pCtx->param[1].param.pz));
|
||||
if (binTypeStr == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int8_t binType = getHistogramBinType(binTypeStr);
|
||||
taosMemoryFree(binTypeStr);
|
||||
|
||||
|
@ -4835,6 +4838,9 @@ int32_t histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResul
|
|||
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
|
||||
}
|
||||
char* binDesc = strndup(varDataVal(pCtx->param[2].param.pz), varDataLen(pCtx->param[2].param.pz));
|
||||
if (binDesc == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int64_t normalized = pCtx->param[3].param.i;
|
||||
if (normalized != 0 && normalized != 1) {
|
||||
taosMemoryFree(binDesc);
|
||||
|
|
|
@ -43,6 +43,10 @@ int32_t tHistogramCreate(int32_t numOfEntries, SHistogramInfo** pHisto) {
|
|||
#if !defined(USE_ARRAYLIST)
|
||||
pHisto->pList = SSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
|
||||
SInsertSupporter* pss = taosMemoryMalloc(sizeof(SInsertSupporter));
|
||||
if (NULL == pss) {
|
||||
taosMemoryFree(*pHisto);
|
||||
return terrno;
|
||||
}
|
||||
pss->numOfEntries = pHisto->maxEntries;
|
||||
pss->pSkipList = pHisto->pList;
|
||||
|
||||
|
@ -119,6 +123,9 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
|
|||
#else
|
||||
tSkipListKey key = tSkipListCreateKey(TSDB_DATA_TYPE_DOUBLE, &val, tDataTypes[TSDB_DATA_TYPE_DOUBLE].nSize);
|
||||
SHistBin* entry = taosMemoryCalloc(1, sizeof(SHistBin));
|
||||
if (entry == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
entry->val = val;
|
||||
|
||||
tSkipListNode* pResNode = SSkipListPut((*pHisto)->pList, entry, &key, 0);
|
||||
|
|
|
@ -4353,10 +4353,16 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
|
|||
int32_t totalCount = 0;
|
||||
|
||||
char *binTypeStr = strndup(varDataVal(pInput[1].columnData->pData), varDataLen(pInput[1].columnData->pData));
|
||||
if (NULL == binTypeStr) {
|
||||
SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
int8_t binType = getHistogramBinType(binTypeStr);
|
||||
taosMemoryFree(binTypeStr);
|
||||
|
||||
char *binDesc = strndup(varDataVal(pInput[2].columnData->pData), varDataLen(pInput[2].columnData->pData));
|
||||
if (NULL == binDesc) {
|
||||
SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
int64_t normalized = *(int64_t *)(pInput[3].columnData->pData);
|
||||
|
||||
int32_t type = GET_PARAM_TYPE(pInput);
|
||||
|
|
|
@ -596,6 +596,11 @@ int32_t ncharTobinary(void *buf, void **out) { // todo need to remove , if tobi
|
|||
int32_t inputLen = varDataTLen(buf);
|
||||
|
||||
*out = taosMemoryCalloc(1, inputLen);
|
||||
if (NULL == *out) {
|
||||
sclError("charset:%s to %s. val:%s convert ncharTobinary failed, since memory alloc failed.",
|
||||
DEFAULT_UNICODE_ENCODEC, tsCharset, (char *)varDataVal(buf));
|
||||
SCL_ERR_RET(terrno);
|
||||
}
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(*out));
|
||||
if (len < 0) {
|
||||
sclError("charset:%s to %s. val:%s convert ncharTobinary failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
|
||||
|
|
Loading…
Reference in New Issue