From dcc30f427e91f500b55aa766700773367495b351 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 13 Jan 2021 10:43:45 +0800 Subject: [PATCH] add client check --- src/client/src/TSDBJNIConnector.c | 4 +- src/client/src/tscAsync.c | 6 +-- src/client/src/tscLocal.c | 28 ++++++------- src/client/src/tscLocalMerge.c | 44 ++++++++++----------- src/client/src/tscParseInsert.c | 10 ++--- src/client/src/tscPrepare.c | 14 +++---- src/client/src/tscProfile.c | 2 +- src/client/src/tscSQLParser.c | 30 +++++++------- src/client/src/tscSchemaUtil.c | 2 +- src/client/src/tscServer.c | 16 ++++---- src/client/src/tscSql.c | 20 +++++----- src/client/src/tscStream.c | 6 +-- src/client/src/tscSub.c | 6 +-- src/client/src/tscSubquery.c | 32 +++++++-------- src/client/src/tscUtil.c | 66 +++++++++++++++---------------- 15 files changed, 143 insertions(+), 143 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index a8829499a3..30ee946621 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -289,7 +289,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp( jsize len = (*env)->GetArrayLength(env, jsql); - char *str = (char *) calloc(1, sizeof(char) * (len + 1)); + char *str = (char *) TDMCALLOC(1, sizeof(char) * (len + 1)); if (str == NULL) { jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon); return JNI_OUT_OF_MEMORY; @@ -651,7 +651,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_validateCreateTab jsize len = (*env)->GetArrayLength(env, jsql); - char *str = (char *)calloc(1, sizeof(char) * (len + 1)); + char *str = (char *)TDMCALLOC(1, sizeof(char) * (len + 1)); (*env)->GetByteArrayRegion(env, jsql, 0, len, (jbyte *)str); if ((*env)->ExceptionCheck(env)) { // todo handle error diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index e522d37870..4d9e8b51de 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -52,7 +52,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, __async_cb_func_t fp, void* para registerSqlObj(pSql); - pSql->sqlstr = calloc(1, sqlLen + 1); + pSql->sqlstr = TDMCALLOC(1, sqlLen + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -97,7 +97,7 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa nPrintTsc("%s", sqlstr); - SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); + SSqlObj *pSql = (SSqlObj *)TDMCALLOC(1, sizeof(SSqlObj)); if (pSql == NULL) { tscError("failed to malloc sqlObj"); tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY); @@ -369,7 +369,7 @@ static void tscProcessAsyncError(SSchedMsg *pMsg) { } void tscQueueAsyncError(void(*fp), void *param, int32_t code) { - int32_t* c = malloc(sizeof(int32_t)); + int32_t* c = TDMALLOC(sizeof(int32_t)); *c = code; SSchedMsg schedMsg = { 0 }; diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 8dab88edb2..00eed313c6 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -280,7 +280,7 @@ void tscSCreateCallBack(void *param, TAOS_RES *tres, int code) { taos_fetch_rows_a(tres, tscSCreateCallBack, param); builder->callStage = SCREATE_CALLBACK_RETRIEVE; } else { - char *result = calloc(1, TSDB_MAX_BINARY_LEN); + char *result = TDMCALLOC(1, TSDB_MAX_BINARY_LEN); pRes->code = builder->fp(builder, result); taos_free_result(pSql); @@ -454,7 +454,7 @@ int32_t tscRebuildCreateTableStatement(void *param,char *result) { SCreateBuilder *builder = (SCreateBuilder *)param; int32_t code = TSDB_CODE_SUCCESS; - char *buf = calloc(1,TSDB_MAX_BINARY_LEN); + char *buf = TDMCALLOC(1,TSDB_MAX_BINARY_LEN); if (buf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -512,7 +512,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) { SCreateBuilder *builder = (SCreateBuilder *)param; int32_t code = TSDB_CODE_SUCCESS; - char *buf = calloc(1, TSDB_MAX_BINARY_LEN); + char *buf = TDMCALLOC(1, TSDB_MAX_BINARY_LEN); if (buf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -525,7 +525,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) { } static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) { - char *buf = (char *)malloc(TSDB_MAX_BINARY_LEN); + char *buf = (char *)TDMALLOC(TSDB_MAX_BINARY_LEN); if (buf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -557,12 +557,12 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMeta * pMeta = pTableMetaInfo->pTableMeta; - SSqlObj *pInterSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); + SSqlObj *pInterSql = (SSqlObj *)TDMCALLOC(1, sizeof(SSqlObj)); if (pInterSql == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SCreateBuilder *param = (SCreateBuilder *)malloc(sizeof(SCreateBuilder)); + SCreateBuilder *param = (SCreateBuilder *)TDMALLOC(sizeof(SCreateBuilder)); if (param == NULL) { TDMFREE(pInterSql); return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -579,7 +579,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch param->fp = tscRebuildCreateTableStatement; param->callStage = SCREATE_CALLBACK_QUERY; - char *query = (char *)calloc(1, TSDB_MAX_BINARY_LEN); + char *query = (char *)TDMCALLOC(1, TSDB_MAX_BINARY_LEN); if (query == NULL) { TDMFREE(param); TDMFREE(pInterSql); @@ -678,7 +678,7 @@ static int32_t tscProcessShowCreateTable(SSqlObj *pSql) { char tableName[TSDB_TABLE_NAME_LEN] = {0}; extractTableName(pTableMetaInfo->name, tableName); - char *result = (char *)calloc(1, TSDB_MAX_BINARY_LEN); + char *result = (char *)TDMCALLOC(1, TSDB_MAX_BINARY_LEN); int32_t code = TSDB_CODE_SUCCESS; if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { code = tscRebuildDDLForSuperTable(pSql, tableName, result); @@ -702,12 +702,12 @@ static int32_t tscProcessShowCreateDatabase(SSqlObj *pSql) { STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - SSqlObj *pInterSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); + SSqlObj *pInterSql = (SSqlObj *)TDMCALLOC(1, sizeof(SSqlObj)); if (pInterSql == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SCreateBuilder *param = (SCreateBuilder *)malloc(sizeof(SCreateBuilder)); + SCreateBuilder *param = (SCreateBuilder *)TDMALLOC(sizeof(SCreateBuilder)); if (param == NULL) { TDMFREE(pInterSql); return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -729,7 +729,7 @@ static int32_t tscProcessCurrentUser(SSqlObj *pSql) { pExpr->resBytes = TSDB_USER_LEN + TSDB_DATA_TYPE_BINARY; pExpr->resType = TSDB_DATA_TYPE_BINARY; - char* vx = calloc(1, pExpr->resBytes); + char* vx = TDMCALLOC(1, pExpr->resBytes); if (vx == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -755,7 +755,7 @@ static int32_t tscProcessCurrentDB(SSqlObj *pSql) { size_t t = strlen(db); pExpr->resBytes = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE; - char* vx = calloc(1, pExpr->resBytes); + char* vx = TDMCALLOC(1, pExpr->resBytes); if (vx == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -782,7 +782,7 @@ static int32_t tscProcessServerVer(SSqlObj *pSql) { size_t t = strlen(v); pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE); - char* vx = calloc(1, pExpr->resBytes); + char* vx = TDMCALLOC(1, pExpr->resBytes); if (vx == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -805,7 +805,7 @@ static int32_t tscProcessClientVer(SSqlObj *pSql) { size_t t = strlen(version); pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE); - char* v = calloc(1, pExpr->resBytes); + char* v = TDMCALLOC(1, pExpr->resBytes); if (v == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index 0690c8ac53..04b6535005 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -104,13 +104,13 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalReducer *pReducer, tOrderDesc } pCtx->interBufBytes = pExpr->interBytes; - pCtx->resultInfo = calloc(1, pCtx->interBufBytes + sizeof(SResultRowCellInfo)); + pCtx->resultInfo = TDMCALLOC(1, pCtx->interBufBytes + sizeof(SResultRowCellInfo)); pCtx->stableQuery = true; } int16_t n = 0; int16_t tagLen = 0; - SQLFunctionCtx **pTagCtx = calloc(pQueryInfo->fieldsInfo.numOfOutput, POINTER_BYTES); + SQLFunctionCtx **pTagCtx = TDMCALLOC(pQueryInfo->fieldsInfo.numOfOutput, POINTER_BYTES); SQLFunctionCtx *pCtx = NULL; for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { @@ -136,7 +136,7 @@ static SFillColInfo* createFillColInfo(SQueryInfo* pQueryInfo) { int32_t numOfCols = (int32_t)tscNumOfFields(pQueryInfo); int32_t offset = 0; - SFillColInfo* pFillCol = calloc(numOfCols, sizeof(SFillColInfo)); + SFillColInfo* pFillCol = TDMCALLOC(numOfCols, sizeof(SFillColInfo)); for(int32_t i = 0; i < numOfCols; ++i) { SInternalField* pIField = taosArrayGet(pQueryInfo->fieldsInfo.internalField, i); @@ -214,7 +214,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd size_t size = sizeof(SLocalReducer) + POINTER_BYTES * numOfFlush; - SLocalReducer *pReducer = (SLocalReducer *) calloc(1, size); + SLocalReducer *pReducer = (SLocalReducer *) TDMCALLOC(1, size); if (pReducer == NULL) { tscError("%p failed to create local merge structure, out of memory", pSql); @@ -238,7 +238,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd int32_t numOfFlushoutInFile = pMemBuffer[i]->fileMeta.flushoutData.nLength; for (int32_t j = 0; j < numOfFlushoutInFile; ++j) { - SLocalDataSource *ds = (SLocalDataSource *)malloc(sizeof(SLocalDataSource) + pMemBuffer[0]->pageSize); + SLocalDataSource *ds = (SLocalDataSource *)TDMALLOC(sizeof(SLocalDataSource) + pMemBuffer[0]->pageSize); if (ds == NULL) { tscError("%p failed to create merge structure", pSql); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -285,7 +285,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pReducer->numOfBuffer = idx; - SCompareParam *param = malloc(sizeof(SCompareParam)); + SCompareParam *param = TDMALLOC(sizeof(SCompareParam)); if (param == NULL) { TDMFREE(pReducer); return; @@ -308,7 +308,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd // the input data format follows the old format, but output in a new format. // so, all the input must be parsed as old format - pReducer->pCtx = (SQLFunctionCtx *)calloc(tscSqlExprNumOfExprs(pQueryInfo), sizeof(SQLFunctionCtx)); + pReducer->pCtx = (SQLFunctionCtx *)TDMCALLOC(tscSqlExprNumOfExprs(pQueryInfo), sizeof(SQLFunctionCtx)); pReducer->rowSize = pMemBuffer[0]->nElemSize; tscRestoreSQLFuncForSTableQuery(pQueryInfo); @@ -321,15 +321,15 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pReducer->hasPrevRow = false; pReducer->hasUnprocessedRow = false; - pReducer->prevRowOfInput = (char *)calloc(1, pReducer->rowSize); + pReducer->prevRowOfInput = (char *)TDMCALLOC(1, pReducer->rowSize); // used to keep the latest input row - pReducer->pTempBuffer = (tFilePage *)calloc(1, pReducer->rowSize + sizeof(tFilePage)); - pReducer->discardData = (tFilePage *)calloc(1, pReducer->rowSize + sizeof(tFilePage)); + pReducer->pTempBuffer = (tFilePage *)TDMCALLOC(1, pReducer->rowSize + sizeof(tFilePage)); + pReducer->discardData = (tFilePage *)TDMCALLOC(1, pReducer->rowSize + sizeof(tFilePage)); pReducer->discard = false; pReducer->nResultBufSize = pMemBuffer[0]->pageSize * 16; - pReducer->pResultBuf = (tFilePage *)calloc(1, pReducer->nResultBufSize + sizeof(tFilePage)); + pReducer->pResultBuf = (tFilePage *)TDMCALLOC(1, pReducer->nResultBufSize + sizeof(tFilePage)); pReducer->resColModel = finalmodel; pReducer->resColModel->capacity = pReducer->nResultBufSize; @@ -340,7 +340,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd } assert(finalmodel->rowSize > 0 && finalmodel->rowSize <= pReducer->rowSize); - pReducer->pFinalRes = calloc(1, pReducer->rowSize * pReducer->resColModel->capacity); + pReducer->pFinalRes = TDMCALLOC(1, pReducer->rowSize * pReducer->resColModel->capacity); if (pReducer->pTempBuffer == NULL || pReducer->discardData == NULL || pReducer->pResultBuf == NULL || pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) { @@ -553,7 +553,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm numOfGroupByCols++; } - int32_t *orderColIndexList = (int32_t *)calloc(numOfGroupByCols, sizeof(int32_t)); + int32_t *orderColIndexList = (int32_t *)TDMCALLOC(numOfGroupByCols, sizeof(int32_t)); if (orderColIndexList == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -659,7 +659,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - (*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pSql->subState.numOfSub); + (*pMemBuffer) = (tExtMemBuffer **)TDMALLOC(POINTER_BYTES * pSql->subState.numOfSub); if (*pMemBuffer == NULL) { tscError("%p failed to allocate memory", pSql); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -668,7 +668,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr size_t size = tscSqlExprNumOfExprs(pQueryInfo); - pSchema = (SSchema *)calloc(1, sizeof(SSchema) * size); + pSchema = (SSchema *)TDMCALLOC(1, sizeof(SSchema) * size); if (pSchema == NULL) { tscError("%p failed to allocate memory", pSql); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -950,10 +950,10 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO // todo extract function int64_t actualETime = (pQueryInfo->order.order == TSDB_ORDER_ASC)? pQueryInfo->window.ekey: pQueryInfo->window.skey; - tFilePage **pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutput); + tFilePage **pResPages = TDMALLOC(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutput); for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); - pResPages[i] = calloc(1, sizeof(tFilePage) + pField->bytes * pLocalReducer->resColModel->capacity); + pResPages[i] = TDMCALLOC(1, sizeof(tFilePage) + pField->bytes * pLocalReducer->resColModel->capacity); } while (1) { @@ -1134,7 +1134,7 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo assert(maxBufSize >= 0); - char *buf = malloc((size_t)maxBufSize); + char *buf = TDMALLOC((size_t)maxBufSize); for (int32_t k = 0; k < size; ++k) { SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k]; if (pCtx->functionId != TSDB_FUNC_TAG) { @@ -1608,14 +1608,14 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen) pRes->row = 0; pRes->rspType = 0; // used as a flag to denote if taos_retrieved() has been called yet - pRes->pLocalReducer = (SLocalReducer *)calloc(1, sizeof(SLocalReducer)); + pRes->pLocalReducer = (SLocalReducer *)TDMCALLOC(1, sizeof(SLocalReducer)); /* * we need one additional byte space * the sprintf function needs one additional space to put '\0' at the end of string */ size_t allocSize = numOfRes * rowLen + sizeof(tFilePage) + 1; - pRes->pLocalReducer->pResultBuf = (tFilePage *)calloc(1, allocSize); + pRes->pLocalReducer->pResultBuf = (tFilePage *)TDMCALLOC(1, allocSize); pRes->pLocalReducer->pResultBuf->num = numOfRes; pRes->data = pRes->pLocalReducer->pResultBuf->data; @@ -1623,7 +1623,7 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen) int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize) { int32_t maxRowSize = MAX(rowSize, finalRowSize); - char* pbuf = calloc(1, (size_t)(pOutput->num * maxRowSize)); + char* pbuf = TDMCALLOC(1, (size_t)(pOutput->num * maxRowSize)); size_t size = tscNumOfFields(pQueryInfo); SArithmeticSupport arithSup = {0}; @@ -1632,7 +1632,7 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_ arithSup.offset = 0; arithSup.numOfCols = (int32_t) tscSqlExprNumOfExprs(pQueryInfo); arithSup.exprList = pQueryInfo->exprList; - arithSup.data = calloc(arithSup.numOfCols, POINTER_BYTES); + arithSup.data = TDMCALLOC(arithSup.numOfCols, POINTER_BYTES); for(int32_t k = 0; k < arithSup.numOfCols; ++k) { SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k); diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index e060a201b2..609897e728 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -624,7 +624,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3 remain = pDataBlock->nAllocSize - pDataBlock->size; } - char *tmp = realloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); + char *tmp = TDMREALLOC(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); if (tmp != NULL) { pDataBlock->pData = tmp; memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size); @@ -715,7 +715,7 @@ static int32_t doParseInsertStatement(SSqlCmd* pCmd, char **str, SParsedDataColI } int32_t code = TSDB_CODE_TSC_INVALID_SQL; - char * tmpTokenBuf = calloc(1, 16*1024); // used for deleting Escape character: \\, \', \" + char * tmpTokenBuf = TDMCALLOC(1, 16*1024); // used for deleting Escape character: \\, \', \" if (NULL == tmpTokenBuf) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -950,7 +950,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { tdSortKVRowByColIdx(row); pCmd->tagData.dataLen = kvRowLen(row); - char* pTag = realloc(pCmd->tagData.data, pCmd->tagData.dataLen); + char* pTag = TDMREALLOC(pCmd->tagData.data, pCmd->tagData.dataLen); if (pTag == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1476,7 +1476,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { } tscAllocateMemIfNeed(pTableDataBlock, tinfo.rowSize, &maxRows); - char *tokenBuf = calloc(1, 4096); + char *tokenBuf = TDMCALLOC(1, 4096); while ((readLen = tgetline(&line, &n, fp)) != -1) { if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) { @@ -1535,7 +1535,7 @@ void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql) { assert(pCmd->dataSourceType == DATA_FROM_DATA_FILE && strlen(pCmd->payload) != 0); - SImportFileSupport *pSupporter = calloc(1, sizeof(SImportFileSupport)); + SImportFileSupport *pSupporter = TDMCALLOC(1, sizeof(SImportFileSupport)); SSqlObj *pNew = createSubqueryObj(pSql, 0, parseFileSendDataBlock, pSupporter, TSDB_SQL_INSERT, NULL); pCmd->count = 1; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index e97e9467c9..eaf41c40b7 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -54,7 +54,7 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_ uint16_t size = stmt->numParts + 1; if (size > stmt->sizeParts) { size *= 2; - void* tmp = realloc(stmt->parts, sizeof(SNormalStmtPart) * size); + void* tmp = TDMREALLOC(stmt->parts, sizeof(SNormalStmtPart) * size); if (tmp == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -125,7 +125,7 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: - var->pz = (char*)malloc((*tb->length) + 1); + var->pz = (char*)TDMALLOC((*tb->length) + 1); if (var->pz == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -179,7 +179,7 @@ static int normalStmtPrepare(STscStmt* stmt) { } if (normal->numParams > 0) { - normal->params = calloc(normal->numParams, sizeof(tVariant)); + normal->params = TDMCALLOC(normal->numParams, sizeof(tVariant)); if (normal->params == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -714,7 +714,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { totalDataSize += dataSize + sizeof(SSubmitBlk); if (totalDataSize > pBlock->nAllocSize) { const double factor = 1.5; - void* tmp = realloc(pBlock->pData, (uint32_t)(totalDataSize * factor)); + void* tmp = TDMREALLOC(pBlock->pData, (uint32_t)(totalDataSize * factor)); if (tmp == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -850,7 +850,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { return NULL; } - STscStmt* pStmt = calloc(1, sizeof(STscStmt)); + STscStmt* pStmt = TDMCALLOC(1, sizeof(STscStmt)); if (pStmt == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); @@ -858,7 +858,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { } pStmt->taos = pObj; - SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); + SSqlObj* pSql = TDMCALLOC(1, sizeof(SSqlObj)); if (pSql == NULL) { TDMFREE(pStmt); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -897,7 +897,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); + pSql->sqlstr = TDMREALLOC(pSql->sqlstr, sqlLen + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 935526f451..bf405b6a1d 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -102,7 +102,7 @@ void tscSaveSlowQuery(SSqlObj *pSql) { tscDebug("%p query time:%" PRId64 " sql:%s", pSql, pSql->res.useconds, pSql->sqlstr); int32_t sqlSize = (int32_t)(TSDB_SLOW_QUERY_SQL_LEN + size); - char *sql = malloc(sqlSize); + char *sql = TDMALLOC(sqlSize); if (sql == NULL) { tscError("%p failed to allocate memory to sent slow query to dnode", pSql); return; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 299bf0a0c0..30fa005490 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1386,7 +1386,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t SInternalField* pInfo = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, slot); if (pInfo->pSqlExpr == NULL) { - SExprInfo* pArithExprInfo = calloc(1, sizeof(SExprInfo)); + SExprInfo* pArithExprInfo = TDMCALLOC(1, sizeof(SExprInfo)); // arithmetic expression always return result in the format of double float pArithExprInfo->bytes = sizeof(double); @@ -2980,7 +2980,7 @@ static SColumnFilterInfo* addColumnFilterInfo(SColumn* pColumn) { int32_t size = pColumn->numOfFilters + 1; - char* tmp = (char*) realloc((void*)(pColumn->filterInfo), sizeof(SColumnFilterInfo) * (size)); + char* tmp = (char*) TDMREALLOC((void*)(pColumn->filterInfo), sizeof(SColumnFilterInfo) * (size)); if (tmp != NULL) { pColumn->filterInfo = (SColumnFilterInfo*)tmp; } else { @@ -3022,13 +3022,13 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, // TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd } else if (colType == TSDB_DATA_TYPE_BINARY) { - pColumnFilter->pz = (int64_t)calloc(1, pRight->val.nLen + TSDB_NCHAR_SIZE); + pColumnFilter->pz = (int64_t)TDMCALLOC(1, pRight->val.nLen + TSDB_NCHAR_SIZE); pColumnFilter->len = pRight->val.nLen; retVal = tVariantDump(&pRight->val, (char*)pColumnFilter->pz, colType, false); } else if (colType == TSDB_DATA_TYPE_NCHAR) { // pRight->val.nLen + 1 is larger than the actual nchar string length - pColumnFilter->pz = (int64_t)calloc(1, (pRight->val.nLen + 1) * TSDB_NCHAR_SIZE); + pColumnFilter->pz = (int64_t)TDMCALLOC(1, (pRight->val.nLen + 1) * TSDB_NCHAR_SIZE); retVal = tVariantDump(&pRight->val, (char*)pColumnFilter->pz, colType, false); size_t len = twcslen((wchar_t*)pColumnFilter->pz); pColumnFilter->len = len * TSDB_NCHAR_SIZE; @@ -4494,7 +4494,7 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery size_t size = tscNumOfFields(pQueryInfo); if (pQueryInfo->fillVal == NULL) { - pQueryInfo->fillVal = calloc(size, sizeof(int64_t)); + pQueryInfo->fillVal = TDMCALLOC(size, sizeof(int64_t)); if (pQueryInfo->fillVal == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -4935,7 +4935,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { tVariantListItem* pItem = taosArrayGet(pVarList, 1); SSchema* pTagsSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, columnIndex.columnIndex); - pAlterSQL->tagData.data = calloc(1, pTagsSchema->bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + pAlterSQL->tagData.data = TDMCALLOC(1, pTagsSchema->bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); if (tVariantDump(&pItem->pVar, pAlterSQL->tagData.data, pTagsSchema->type, true) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg13); @@ -6268,7 +6268,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { pTag->dataLen = kvRowLen(row); if (pTag->data == NULL) { - pTag->data = malloc(pTag->dataLen); + pTag->data = TDMALLOC(pTag->dataLen); } kvRowCpy(pTag->data, row); @@ -6676,23 +6676,23 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS } if (pSqlExpr->pLeft == NULL && pSqlExpr->pRight == NULL && pSqlExpr->nSQLOptr == 0) { - *pExpr = calloc(1, sizeof(tExprNode)); + *pExpr = TDMCALLOC(1, sizeof(tExprNode)); return TSDB_CODE_SUCCESS; } if (pSqlExpr->pLeft == NULL) { if (pSqlExpr->nSQLOptr >= TK_BOOL && pSqlExpr->nSQLOptr <= TK_STRING) { - *pExpr = calloc(1, sizeof(tExprNode)); + *pExpr = TDMCALLOC(1, sizeof(tExprNode)); (*pExpr)->nodeType = TSQL_NODE_VALUE; - (*pExpr)->pVal = calloc(1, sizeof(tVariant)); + (*pExpr)->pVal = TDMCALLOC(1, sizeof(tVariant)); tVariantAssign((*pExpr)->pVal, &pSqlExpr->val); return TSDB_CODE_SUCCESS; } else if (pSqlExpr->nSQLOptr >= TK_COUNT && pSqlExpr->nSQLOptr <= TK_AVG_IRATE) { // arithmetic expression on the results of aggregation functions - *pExpr = calloc(1, sizeof(tExprNode)); + *pExpr = TDMCALLOC(1, sizeof(tExprNode)); (*pExpr)->nodeType = TSQL_NODE_COL; - (*pExpr)->pSchema = calloc(1, sizeof(SSchema)); + (*pExpr)->pSchema = TDMCALLOC(1, sizeof(SSchema)); strncpy((*pExpr)->pSchema->name, pSqlExpr->operand.z, pSqlExpr->operand.n); // set the input column data byte and type. @@ -6723,9 +6723,9 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; int32_t numOfColumns = tscGetNumOfColumns(pTableMeta); - *pExpr = calloc(1, sizeof(tExprNode)); + *pExpr = TDMCALLOC(1, sizeof(tExprNode)); (*pExpr)->nodeType = TSQL_NODE_COL; - (*pExpr)->pSchema = calloc(1, sizeof(SSchema)); + (*pExpr)->pSchema = TDMCALLOC(1, sizeof(SSchema)); SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, index.columnIndex); *(*pExpr)->pSchema = *pSchema; @@ -6746,7 +6746,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS } } else { - *pExpr = (tExprNode *)calloc(1, sizeof(tExprNode)); + *pExpr = (tExprNode *)TDMCALLOC(1, sizeof(tExprNode)); (*pExpr)->nodeType = TSQL_NODE_EXPR; (*pExpr)->_node.hasPK = false; diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index 123f0fd222..650304b385 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -152,7 +152,7 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg) { assert(pTableMetaMsg != NULL && pTableMetaMsg->numOfColumns >= 2 && pTableMetaMsg->numOfTags >= 0); int32_t schemaSize = (pTableMetaMsg->numOfColumns + pTableMetaMsg->numOfTags) * sizeof(SSchema); - STableMeta* pTableMeta = calloc(1, sizeof(STableMeta) + schemaSize); + STableMeta* pTableMeta = TDMCALLOC(1, sizeof(STableMeta) + schemaSize); pTableMeta->tableType = pTableMetaMsg->tableType; pTableMeta->vgId = pTableMetaMsg->vgroup.vgId; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index ac9a8199ed..022d87245f 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -201,7 +201,7 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { } if (pRes->length == NULL) { - pRes->length = calloc(2, sizeof(int32_t)); + pRes->length = TDMCALLOC(2, sizeof(int32_t)); } pRes->length[0] = total; @@ -209,7 +209,7 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { } else { tscDebug("%" PRId64 " heartbeat failed, code:%s", pObj->hbrid, tstrerror(code)); if (pRes->length == NULL) { - pRes->length = calloc(2, sizeof(int32_t)); + pRes->length = TDMCALLOC(2, sizeof(int32_t)); } pRes->length[1] = 0; @@ -386,7 +386,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { pRes->rspLen = rpcMsg->contLen; if (pRes->rspLen > 0 && rpcMsg->pCont) { - char *tmp = (char *)realloc(pRes->pRsp, pRes->rspLen); + char *tmp = (char *)TDMREALLOC(pRes->pRsp, pRes->rspLen); if (tmp == NULL) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; } else { @@ -2026,7 +2026,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) { size_t size = sizeof(SVgroupMsg) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsMsg); size_t vgroupsz = sizeof(SVgroupInfo) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsInfo); - pInfo->vgroupList = calloc(1, vgroupsz); + pInfo->vgroupList = TDMCALLOC(1, vgroupsz); assert(pInfo->vgroupList != NULL); pInfo->vgroupList->numOfVgroups = pVgroupMsg->numOfVgroups; @@ -2114,7 +2114,7 @@ static void createHBObj(STscObj* pObj) { return; } - SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); + SSqlObj *pSql = (SSqlObj *)TDMCALLOC(1, sizeof(SSqlObj)); if (NULL == pSql) return; pSql->fp = tscProcessHeartBeatRsp; @@ -2304,7 +2304,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { void tscTableMetaCallBack(void *param, TAOS_RES *res, int code); static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { - SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); + SSqlObj *pNew = TDMCALLOC(1, sizeof(SSqlObj)); if (NULL == pNew) { tscError("%p malloc failed for new sqlobj to get table meta", pSql); return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -2364,7 +2364,7 @@ int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { TDMFREE(pTableMetaInfo->pTableMeta); uint32_t size = tscGetTableMetaMaxSize(); - pTableMetaInfo->pTableMeta = calloc(1, size); + pTableMetaInfo->pTableMeta = TDMCALLOC(1, size); pTableMetaInfo->pTableMeta->tableInfo.numOfColumns = -1; int32_t len = (int32_t) strlen(pTableMetaInfo->name); @@ -2437,7 +2437,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { return TSDB_CODE_SUCCESS; } - SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); + SSqlObj *pNew = TDMCALLOC(1, sizeof(SSqlObj)); pNew->pTscObj = pSql->pTscObj; pNew->signature = pNew; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index f6891bdf4d..fbb45159ce 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -97,14 +97,14 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa return NULL; } - STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); + STscObj *pObj = (STscObj *)TDMCALLOC(1, sizeof(STscObj)); if (NULL == pObj) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); return NULL; } // set up tscObj's mgmtEpSet - pObj->tscCorMgmtEpSet = (SRpcCorEpSet *)malloc(sizeof(SRpcCorEpSet)); + pObj->tscCorMgmtEpSet = (SRpcCorEpSet *)TDMALLOC(sizeof(SRpcCorEpSet)); if (NULL == pObj->tscCorMgmtEpSet) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); @@ -140,7 +140,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa pthread_mutex_init(&pObj->mutex, NULL); - SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); + SSqlObj *pSql = (SSqlObj *)TDMCALLOC(1, sizeof(SSqlObj)); if (NULL == pSql) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); @@ -329,7 +329,7 @@ TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen, int64_t* nPrintTsc("%s", sqlstr); - SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); + SSqlObj* pSql = TDMCALLOC(1, sizeof(SSqlObj)); if (pSql == NULL) { tscError("failed to malloc sqlObj"); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -416,7 +416,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { SFieldInfo *pFieldInfo = &pQueryInfo->fieldsInfo; if (pFieldInfo->final == NULL) { - TAOS_FIELD* f = calloc(pFieldInfo->numOfOutput, sizeof(TAOS_FIELD)); + TAOS_FIELD* f = TDMCALLOC(pFieldInfo->numOfOutput, sizeof(TAOS_FIELD)); int32_t j = 0; for(int32_t i = 0; i < pFieldInfo->numOfOutput; ++i) { @@ -867,7 +867,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { return TSDB_CODE_TSC_DISCONNECTED; } - SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); + SSqlObj* pSql = TDMCALLOC(1, sizeof(SSqlObj)); pSql->pTscObj = taos; pSql->signature = pSql; @@ -888,7 +888,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { return TSDB_CODE_TSC_EXCEED_SQL_LIMIT; } - pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); + pSql->sqlstr = TDMREALLOC(pSql->sqlstr, sqlLen + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pSql), pObj); @@ -985,7 +985,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t } if (payloadLen + strlen(pTableMetaInfo->name) + 128 >= pCmd->allocSize) { - char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen); + char *pNewMem = TDMREALLOC(pCmd->payload, pCmd->allocSize + tblListLen); if (pNewMem == NULL) { code = TSDB_CODE_TSC_OUT_OF_MEMORY; sprintf(pCmd->payload, "failed to allocate memory"); @@ -1015,7 +1015,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { return TSDB_CODE_TSC_DISCONNECTED; } - SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); + SSqlObj* pSql = TDMCALLOC(1, sizeof(SSqlObj)); pSql->pTscObj = taos; pSql->signature = pSql; @@ -1035,7 +1035,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { return TSDB_CODE_TSC_INVALID_SQL; } - char *str = calloc(1, tblListLen + 1); + char *str = TDMCALLOC(1, tblListLen + 1); if (str == NULL) { tscError("%p failed to malloc sql string buffer", pSql); tscFreeSqlObj(pSql); diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 91ca13cdaa..94c2de83de 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -569,7 +569,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) return NULL; - SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); + SSqlObj *pSql = (SSqlObj *)TDMCALLOC(1, sizeof(SSqlObj)); if (pSql == NULL) { return NULL; } @@ -580,7 +580,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; - SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream)); + SSqlStream *pStream = (SSqlStream *)TDMCALLOC(1, sizeof(SSqlStream)); if (pStream == NULL) { tscError("%p open stream failed, sql:%s, reason:%s, code:0x%08x", pSql, sqlstr, pCmd->payload, pRes->code); tscFreeSqlObj(pSql); @@ -596,7 +596,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p pSql->param = pStream; pSql->maxRetry = TSDB_MAX_REPLICA; - pSql->sqlstr = calloc(1, strlen(sqlstr) + 1); + pSql->sqlstr = TDMCALLOC(1, strlen(sqlstr) + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); tscFreeSqlObj(pSql); diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 1ea47428ce..76a76d91f5 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -96,7 +96,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* int code = TSDB_CODE_SUCCESS, line = __LINE__; SSqlObj* pSql = NULL; - SSub* pSub = calloc(1, sizeof(SSub)); + SSub* pSub = TDMCALLOC(1, sizeof(SSub)); if (pSub == NULL) { line = __LINE__; code = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -117,7 +117,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* goto fail; } - pSql = calloc(1, sizeof(SSqlObj)); + pSql = TDMCALLOC(1, sizeof(SSqlObj)); if (pSql == NULL) { line = __LINE__; code = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -423,7 +423,7 @@ TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char } SSqlObj* recreateSqlObj(SSub* pSub) { - SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); + SSqlObj* pSql = TDMCALLOC(1, sizeof(SSqlObj)); if (pSql == NULL) { return NULL; } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index a45160beb1..4f53e054ad 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -208,7 +208,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ // todo handle failed to create sub query SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, int32_t index) { - SJoinSupporter* pSupporter = calloc(1, sizeof(SJoinSupporter)); + SJoinSupporter* pSupporter = TDMCALLOC(1, sizeof(SJoinSupporter)); if (pSupporter == NULL) { return NULL; } @@ -802,7 +802,7 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow size_t length = pSupporter->totalLen + validLen; // todo handle memory error - char* tmp = realloc(pSupporter->pIdTagList, length); + char* tmp = TDMREALLOC(pSupporter->pIdTagList, length); if (tmp == NULL) { tscError("%p failed to malloc memory", pSql); @@ -1324,7 +1324,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); int32_t numOfExprs = (int32_t)tscSqlExprNumOfExprs(pQueryInfo); - pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * numOfExprs); + pRes->pColumnIndex = TDMCALLOC(1, sizeof(SColumnIndex) * numOfExprs); if (pRes->pColumnIndex == NULL) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; @@ -1455,7 +1455,7 @@ int32_t tscCreateJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter assert(pSql->res.numOfRows == 0); if (pSql->pSubs == NULL) { - pSql->pSubs = calloc(pSql->subState.numOfSub, POINTER_BYTES); + pSql->pSubs = TDMCALLOC(pSql->subState.numOfSub, POINTER_BYTES); if (pSql->pSubs == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1705,7 +1705,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { return ret; } - pSql->pSubs = calloc(pState->numOfSub, POINTER_BYTES); + pSql->pSubs = TDMCALLOC(pState->numOfSub, POINTER_BYTES); tscDebug("%p retrieved query data from %d vnode(s)", pSql, pState->numOfSub); @@ -1723,7 +1723,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { int32_t i = 0; for (; i < pState->numOfSub; ++i) { - SRetrieveSupport *trs = (SRetrieveSupport *)calloc(1, sizeof(SRetrieveSupport)); + SRetrieveSupport *trs = (SRetrieveSupport *)TDMCALLOC(1, sizeof(SRetrieveSupport)); if (trs == NULL) { tscError("%p failed to malloc buffer for SRetrieveSupport, orderOfSub:%d, reason:%s", pSql, i, strerror(errno)); break; @@ -1732,7 +1732,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { trs->pExtMemBuffer = pMemoryBuf; trs->pOrderDescriptor = pDesc; - trs->localBuffer = (tFilePage *)calloc(1, nBufferSize + sizeof(tFilePage)); + trs->localBuffer = (tFilePage *)TDMCALLOC(1, nBufferSize + sizeof(tFilePage)); if (trs->localBuffer == NULL) { tscError("%p failed to malloc buffer for local buffer, orderOfSub:%d, reason:%s", pSql, i, strerror(errno)); TDMFREE(trs); @@ -2346,7 +2346,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { if (pSql->pSubs != NULL) { for(int32_t i = 0; i < pSql->subState.numOfSub; ++i) { SSqlObj* pSub = pSql->pSubs[i]; - SInsertSupporter* pSup = calloc(1, sizeof(SInsertSupporter)); + SInsertSupporter* pSup = TDMCALLOC(1, sizeof(SInsertSupporter)); pSup->index = i; pSup->pSql = pSql; @@ -2369,7 +2369,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { int32_t numOfSub = 0; pSql->subState.numOfRemain = pSql->subState.numOfSub; - pSql->pSubs = calloc(pSql->subState.numOfSub, POINTER_BYTES); + pSql->pSubs = TDMCALLOC(pSql->subState.numOfSub, POINTER_BYTES); if (pSql->pSubs == NULL) { goto _error; } @@ -2377,7 +2377,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { tscDebug("%p submit data to %d vnode(s)", pSql, pSql->subState.numOfSub); while(numOfSub < pSql->subState.numOfSub) { - SInsertSupporter* pSupporter = calloc(1, sizeof(SInsertSupporter)); + SInsertSupporter* pSupporter = TDMCALLOC(1, sizeof(SInsertSupporter)); if (pSupporter == NULL) { goto _error; } @@ -2467,7 +2467,7 @@ static void doBuildResFromSubqueries(SSqlObj* pSql) { int32_t rowSize = tscGetResRowLength(pQueryInfo->exprList); assert(numOfRes * rowSize > 0); - char* tmp = realloc(pRes->pRsp, numOfRes * rowSize + sizeof(tFilePage)); + char* tmp = TDMREALLOC(pRes->pRsp, numOfRes * rowSize + sizeof(tFilePage)); if (tmp == NULL) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; @@ -2532,10 +2532,10 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex); pRes->numOfCols = (int16_t) tscSqlExprNumOfExprs(pQueryInfo); - pRes->tsrow = calloc(pRes->numOfCols, POINTER_BYTES); - pRes->urow = calloc(pRes->numOfCols, POINTER_BYTES); - pRes->buffer = calloc(pRes->numOfCols, POINTER_BYTES); - pRes->length = calloc(pRes->numOfCols, sizeof(int32_t)); + pRes->tsrow = TDMCALLOC(pRes->numOfCols, POINTER_BYTES); + pRes->urow = TDMCALLOC(pRes->numOfCols, POINTER_BYTES); + pRes->buffer = TDMCALLOC(pRes->numOfCols, POINTER_BYTES); + pRes->length = TDMCALLOC(pRes->numOfCols, sizeof(int32_t)); if (pRes->tsrow == NULL || pRes->buffer == NULL || pRes->length == NULL) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -2561,7 +2561,7 @@ static UNUSED_FUNC void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TA if (pRes->tsrow[columnIndex] != NULL && pField->type == TSDB_DATA_TYPE_NCHAR) { // convert unicode to native code in a temporary buffer extra one byte for terminated symbol if (pRes->buffer[columnIndex] == NULL) { - pRes->buffer[columnIndex] = malloc(pField->bytes + TSDB_NCHAR_SIZE); + pRes->buffer[columnIndex] = TDMALLOC(pField->bytes + TSDB_NCHAR_SIZE); } /* string terminated char for binary data*/ diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 896efe46c2..db15e2140b 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -265,10 +265,10 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { if (pRes->tsrow == NULL) { pRes->numOfCols = pQueryInfo->fieldsInfo.numOfOutput; - pRes->tsrow = calloc(pRes->numOfCols, POINTER_BYTES); - pRes->urow = calloc(pRes->numOfCols, POINTER_BYTES); - pRes->length = calloc(pRes->numOfCols, sizeof(int32_t)); - pRes->buffer = calloc(pRes->numOfCols, POINTER_BYTES); + pRes->tsrow = TDMCALLOC(pRes->numOfCols, POINTER_BYTES); + pRes->urow = TDMCALLOC(pRes->numOfCols, POINTER_BYTES); + pRes->length = TDMCALLOC(pRes->numOfCols, sizeof(int32_t)); + pRes->buffer = TDMCALLOC(pRes->numOfCols, POINTER_BYTES); // not enough memory if (pRes->tsrow == NULL || pRes->urow == NULL || pRes->length == NULL || (pRes->buffer == NULL && pRes->numOfCols > 0)) { @@ -322,7 +322,7 @@ void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo) { } else if (pInfo->field.type == TSDB_DATA_TYPE_NCHAR) { // convert unicode to native code in a temporary buffer extra one byte for terminated symbol - pRes->buffer[i] = realloc(pRes->buffer[i], pInfo->field.bytes * pRes->numOfRows); + pRes->buffer[i] = TDMREALLOC(pRes->buffer[i], pInfo->field.bytes * pRes->numOfRows); // string terminated char for binary data memset(pRes->buffer[i], 0, pInfo->field.bytes * pRes->numOfRows); @@ -531,7 +531,7 @@ SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint uint32_t needed = pDataBlock->numOfParams + 1; if (needed > pDataBlock->numOfAllocedParams) { needed *= 2; - void* tmp = realloc(pDataBlock->params, needed * sizeof(SParamInfo)); + void* tmp = TDMREALLOC(pDataBlock->params, needed * sizeof(SParamInfo)); if (tmp == NULL) { return NULL; } @@ -636,7 +636,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) { */ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks) { - STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks)); + STableDataBlocks* dataBuf = (STableDataBlocks*)TDMCALLOC(1, sizeof(STableDataBlocks)); if (dataBuf == NULL) { tscError("failed to allocated memory, reason:%s", strerror(errno)); return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -648,7 +648,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff dataBuf->nAllocSize = dataBuf->headerSize*2; } - dataBuf->pData = calloc(1, dataBuf->nAllocSize); + dataBuf->pData = TDMCALLOC(1, dataBuf->nAllocSize); if (dataBuf->pData == NULL) { tscError("failed to allocated memory, reason:%s", strerror(errno)); TDMFREE(dataBuf); @@ -773,7 +773,7 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) { static void extractTableNameList(SSqlCmd* pCmd) { pCmd->numOfTables = (int32_t) taosHashGetSize(pCmd->pTableBlockHashList); - pCmd->pTableNameList = calloc(pCmd->numOfTables, POINTER_BYTES); + pCmd->pTableNameList = TDMCALLOC(pCmd->numOfTables, POINTER_BYTES); STableDataBlocks **p1 = taosHashIterate(pCmd->pTableBlockHashList, NULL); int32_t i = 0; @@ -818,7 +818,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql) { dataBuf->nAllocSize = (uint32_t)(dataBuf->nAllocSize * 1.5); } - char* tmp = realloc(dataBuf->pData, dataBuf->nAllocSize); + char* tmp = TDMREALLOC(dataBuf->pData, dataBuf->nAllocSize); if (tmp != NULL) { dataBuf->pData = tmp; memset(dataBuf->pData + dataBuf->size, 0, dataBuf->nAllocSize - dataBuf->size); @@ -912,12 +912,12 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) { if (pCmd->payload == NULL) { assert(pCmd->allocSize == 0); - pCmd->payload = (char*)calloc(1, size); + pCmd->payload = (char*)TDMCALLOC(1, size); if (pCmd->payload == NULL) return TSDB_CODE_TSC_OUT_OF_MEMORY; pCmd->allocSize = size; } else { if (pCmd->allocSize < (uint32_t)size) { - char* b = realloc(pCmd->payload, size); + char* b = TDMREALLOC(pCmd->payload, size); if (b == NULL) return TSDB_CODE_TSC_OUT_OF_MEMORY; pCmd->payload = b; pCmd->allocSize = size; @@ -1061,7 +1061,7 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol int16_t size, int16_t resColId, int16_t interSize, int32_t colType) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pColIndex->tableIndex); - SSqlExpr* pExpr = calloc(1, sizeof(SSqlExpr)); + SSqlExpr* pExpr = TDMCALLOC(1, sizeof(SSqlExpr)); if (pExpr == NULL) { return NULL; } @@ -1196,7 +1196,7 @@ int32_t tscSqlExprCopy(SArray* dst, const SArray* src, uint64_t uid, bool deepco if (pExpr->uid == uid) { if (deepcopy) { - SSqlExpr* p1 = calloc(1, sizeof(SSqlExpr)); + SSqlExpr* p1 = TDMCALLOC(1, sizeof(SSqlExpr)); if (p1 == NULL) { return -1; } @@ -1240,7 +1240,7 @@ SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) { } if (i >= numOfCols || numOfCols == 0) { - SColumn* b = calloc(1, sizeof(SColumn)); + SColumn* b = TDMCALLOC(1, sizeof(SColumn)); if (b == NULL) { return NULL; } @@ -1251,7 +1251,7 @@ SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) { SColumn* pCol = taosArrayGetP(pColumnList, i); if (i < numOfCols && (pCol->colIndex.columnIndex > col || pCol->colIndex.tableIndex != pColIndex->tableIndex)) { - SColumn* b = calloc(1, sizeof(SColumn)); + SColumn* b = TDMCALLOC(1, sizeof(SColumn)); if (b == NULL) { return NULL; } @@ -1277,7 +1277,7 @@ static void destroyFilterInfo(SColumnFilterInfo* pFilterInfo, int32_t numOfFilte SColumn* tscColumnClone(const SColumn* src) { assert(src != NULL); - SColumn* dst = calloc(1, sizeof(SColumn)); + SColumn* dst = TDMCALLOC(1, sizeof(SColumn)); if (dst == NULL) { return NULL; } @@ -1537,7 +1537,7 @@ int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) { if (pCond->len > 0) { assert(pCond->cond != NULL); - c.cond = malloc(c.len); + c.cond = TDMALLOC(c.len); if (c.cond == NULL) { return -1; } @@ -1699,14 +1699,14 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) { // todo refactor: remove this structure size_t s = pCmd->numOfClause + 1; - char* tmp = realloc(pCmd->pQueryInfo, s * POINTER_BYTES); + char* tmp = TDMREALLOC(pCmd->pQueryInfo, s * POINTER_BYTES); if (tmp == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } pCmd->pQueryInfo = (SQueryInfo**)tmp; - SQueryInfo* pQueryInfo = calloc(1, sizeof(SQueryInfo)); + SQueryInfo* pQueryInfo = TDMCALLOC(1, sizeof(SQueryInfo)); if (pQueryInfo == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1826,14 +1826,14 @@ void clearAllTableMetaInfo(SQueryInfo* pQueryInfo) { STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta, SVgroupsInfo* vgroupList, SArray* pTagCols, SArray* pVgroupTables) { - void* pAlloc = realloc(pQueryInfo->pTableMetaInfo, (pQueryInfo->numOfTables + 1) * POINTER_BYTES); + void* pAlloc = TDMREALLOC(pQueryInfo->pTableMetaInfo, (pQueryInfo->numOfTables + 1) * POINTER_BYTES); if (pAlloc == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; } pQueryInfo->pTableMetaInfo = pAlloc; - STableMetaInfo* pTableMetaInfo = calloc(1, sizeof(STableMetaInfo)); + STableMetaInfo* pTableMetaInfo = TDMCALLOC(1, sizeof(STableMetaInfo)); if (pTableMetaInfo == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; @@ -1902,7 +1902,7 @@ void registerSqlObj(SSqlObj* pSql) { } SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cmd) { - SSqlObj* pNew = (SSqlObj*)calloc(1, sizeof(SSqlObj)); + SSqlObj* pNew = (SSqlObj*)TDMCALLOC(1, sizeof(SSqlObj)); if (pNew == NULL) { tscError("%p new subquery failed, tableIndex:%d", pSql, 0); return NULL; @@ -1989,7 +1989,7 @@ static void doSetSqlExprAndResultFieldInfo(SQueryInfo* pNewQueryInfo, int64_t ui SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void* param, int32_t cmd, SSqlObj* pPrevSql) { SSqlCmd* pCmd = &pSql->cmd; - SSqlObj* pNew = (SSqlObj*)calloc(1, sizeof(SSqlObj)); + SSqlObj* pNew = (SSqlObj*)TDMCALLOC(1, sizeof(SSqlObj)); if (pNew == NULL) { tscError("%p new subquery failed, tableIndex:%d", pSql, tableIndex); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -2058,7 +2058,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void } if (pQueryInfo->fillType != TSDB_FILL_NONE) { - pNewQueryInfo->fillVal = malloc(pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t)); + pNewQueryInfo->fillVal = TDMALLOC(pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t)); if (pNewQueryInfo->fillVal == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; @@ -2433,7 +2433,7 @@ void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp) { } void* malloc_throw(size_t size) { - void* p = malloc(size); + void* p = TDMALLOC(size); if (p == NULL) { THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } @@ -2441,7 +2441,7 @@ void* malloc_throw(size_t size) { } void* calloc_throw(size_t nmemb, size_t size) { - void* p = calloc(nmemb, size); + void* p = TDMCALLOC(nmemb, size); if (p == NULL) { THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } @@ -2513,7 +2513,7 @@ SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *vgroupList) { } size_t size = sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupList->numOfVgroups; - SVgroupsInfo* pNew = calloc(1, size); + SVgroupsInfo* pNew = TDMCALLOC(1, size); if (pNew == NULL) { return NULL; } @@ -2591,7 +2591,7 @@ int32_t copyTagData(STagData* dst, const STagData* src) { tstrncpy(dst->name, src->name, tListLen(dst->name)); if (dst->dataLen > 0) { - dst->data = malloc(dst->dataLen); + dst->data = TDMALLOC(dst->dataLen); if (dst->data == NULL) { return -1; } @@ -2606,7 +2606,7 @@ STableMeta* createSuperTableMeta(STableMetaMsg* pChild) { assert(pChild != NULL); int32_t total = pChild->numOfColumns + pChild->numOfTags; - STableMeta* pTableMeta = calloc(1, sizeof(STableMeta) + sizeof(SSchema) * total); + STableMeta* pTableMeta = TDMCALLOC(1, sizeof(STableMeta) + sizeof(SSchema) * total); pTableMeta->tableType = TSDB_SUPER_TABLE; pTableMeta->tableInfo.numOfTags = pChild->numOfTags; pTableMeta->tableInfo.numOfColumns = pChild->numOfColumns; @@ -2637,7 +2637,7 @@ uint32_t tscGetTableMetaSize(STableMeta* pTableMeta) { CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta) { assert(pTableMeta != NULL); - CChildTableMeta* cMeta = calloc(1, sizeof(CChildTableMeta)); + CChildTableMeta* cMeta = TDMCALLOC(1, sizeof(CChildTableMeta)); cMeta->tableType = TSDB_CHILD_TABLE; cMeta->vgId = pTableMeta->vgId; cMeta->id = pTableMeta->id; @@ -2650,7 +2650,7 @@ int32_t tscCreateTableMetaFromCChildMeta(STableMeta* pChild, const char* name) { assert(pChild != NULL); uint32_t size = tscGetTableMetaMaxSize(); - STableMeta* p = calloc(1, size); + STableMeta* p = TDMCALLOC(1, size); taosHashGetClone(tscTableMetaInfo, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, p, -1); if (p->id.uid > 0) { // tableMeta exists, build child table meta and return @@ -2679,7 +2679,7 @@ uint32_t tscGetTableMetaMaxSize() { STableMeta* tscTableMetaClone(STableMeta* pTableMeta) { assert(pTableMeta != NULL); uint32_t size = tscGetTableMetaSize(pTableMeta); - STableMeta* p = calloc(1, size); + STableMeta* p = TDMCALLOC(1, size); memcpy(p, pTableMeta, size); return p; } -- GitLab