From 7daaecba049c60b027b357c7911f85bfc1a5beab Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Tue, 5 Jan 2021 11:26:19 +0800 Subject: [PATCH] mem protect --- src/client/src/TSDBJNIConnector.c | 4 +- src/client/src/tscAsync.c | 2 +- src/client/src/tscLocal.c | 40 +++++----- src/client/src/tscLocalMerge.c | 72 +++++++++--------- src/client/src/tscParseInsert.c | 20 ++--- src/client/src/tscPrepare.c | 14 ++-- src/client/src/tscProfile.c | 6 +- src/client/src/tscSQLParser.c | 6 +- src/client/src/tscServer.c | 20 ++--- src/client/src/tscSql.c | 28 +++---- src/client/src/tscStream.c | 8 +- src/client/src/tscSub.c | 4 +- src/client/src/tscSubquery.c | 30 ++++---- src/client/src/tscSystem.c | 2 +- src/client/src/tscUtil.c | 110 +++++++++++++-------------- src/os/inc/osMemory.h | 23 ++++++ src/os/src/detail/osMemory.c | 120 +++++++++++++++++++++++++++++- src/query/src/qAggMain.c | 6 +- src/query/src/qAst.c | 14 ++-- src/query/src/qExecutor.c | 112 ++++++++++++++-------------- src/query/src/qExtbuffer.c | 18 ++--- src/query/src/qFill.c | 16 ++-- src/query/src/qHistogram.c | 4 +- src/query/src/qParserImpl.c | 30 ++++---- src/query/src/qPercentile.c | 12 +-- src/query/src/qResultbuf.c | 12 +-- src/query/src/qTsbuf.c | 16 ++-- src/query/src/qUtil.c | 10 +-- src/query/src/sql.c | 2 +- src/util/src/hash.c | 4 +- 30 files changed, 453 insertions(+), 312 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index a8829499a3..a6191ecad5 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -314,7 +314,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp( } } - free(str); + TDMFREE(str); return (jlong) pSql; } @@ -660,7 +660,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_validateCreateTab int code = taos_validate_sql(tscon, str); jniDebug("jobj:%p, conn:%p, code is %d", jobj, tscon, code); - free(str); + TDMFREE(str); return code; } diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 96aeb9d60d..cfbc5631cb 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -364,7 +364,7 @@ void tscProcessFetchRow(SSchedMsg *pMsg) { static void tscProcessAsyncError(SSchedMsg *pMsg) { void (*fp)() = pMsg->ahandle; terrno = *(int32_t*) pMsg->msg; - tfree(pMsg->msg); + TDMFREE(pMsg->msg); (*fp)(pMsg->thandle, NULL, *(int32_t*)pMsg->msg); } diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 16bbd420c0..e5af633f75 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -271,7 +271,7 @@ void tscSCreateCallBack(void *param, TAOS_RES *tres, int code) { pRes->code = taos_errno(pSql); if (pRes->code != TSDB_CODE_SUCCESS) { taos_free_result(pSql); - free(builder); + TDMFREE(builder); tscAsyncResultOnError(pParentSql); return; } @@ -284,8 +284,8 @@ void tscSCreateCallBack(void *param, TAOS_RES *tres, int code) { pRes->code = builder->fp(builder, result); taos_free_result(pSql); - free(builder); - free(result); + TDMFREE(builder); + TDMFREE(result); if (pRes->code == TSDB_CODE_SUCCESS) { (*pParentSql->fp)(pParentSql->param, pParentSql, code); @@ -464,7 +464,7 @@ int32_t tscRebuildCreateTableStatement(void *param,char *result) { snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE TABLE %s USING %s TAGS %s", builder->buf, builder->sTableName, buf); code = tscSCreateBuildResult(builder->pParentSql, SCREATE_BUILD_TABLE, builder->buf, result); } - free(buf); + TDMFREE(buf); return code; } @@ -520,7 +520,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) { if (code == TSDB_CODE_SUCCESS) { code = tscSCreateBuildResult(builder->pParentSql, SCREATE_BUILD_DB, builder->buf, buf); } - free(buf); + TDMFREE(buf); return code; } @@ -534,7 +534,7 @@ static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) { STableMeta *pMeta = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0)->pTableMeta; if (pMeta->tableType == TSDB_SUPER_TABLE || pMeta->tableType == TSDB_NORMAL_TABLE || pMeta->tableType == TSDB_STREAM_TABLE) { - free(buf); + TDMFREE(buf); return TSDB_CODE_TSC_INVALID_VALUE; } @@ -564,7 +564,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch SCreateBuilder *param = (SCreateBuilder *)malloc(sizeof(SCreateBuilder)); if (param == NULL) { - free(pInterSql); + TDMFREE(pInterSql); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -581,24 +581,24 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch char *query = (char *)calloc(1, TSDB_MAX_BINARY_LEN); if (query == NULL) { - free(param); - free(pInterSql); + TDMFREE(param); + TDMFREE(pInterSql); return TSDB_CODE_TSC_OUT_OF_MEMORY; } char *columns = NULL; int32_t code = tscGetTableTagColumnName(pSql, &columns) ; if (code != TSDB_CODE_SUCCESS) { - free(param); - free(pInterSql); - free(query); + TDMFREE(param); + TDMFREE(pInterSql); + TDMFREE(query); return code; } snprintf(query + strlen(query), TSDB_MAX_BINARY_LEN - strlen(query), "SELECT %s FROM %s WHERE TBNAME IN(\'%s\')", columns, fullName, param->buf); doAsyncQuery(pSql->pTscObj, pInterSql, tscSCreateCallBack, param, query, strlen(query)); - free(query); - free(columns); + TDMFREE(query); + TDMFREE(columns); return TSDB_CODE_TSC_ACTION_IN_PROGRESS; } @@ -693,7 +693,7 @@ static int32_t tscProcessShowCreateTable(SSqlObj *pSql) { if (code == TSDB_CODE_SUCCESS) { code = tscSCreateBuildResult(pSql, SCREATE_BUILD_TABLE, tableName, result); } - free(result); + TDMFREE(result); return code; } @@ -709,7 +709,7 @@ static int32_t tscProcessShowCreateDatabase(SSqlObj *pSql) { SCreateBuilder *param = (SCreateBuilder *)malloc(sizeof(SCreateBuilder)); if (param == NULL) { - free(pInterSql); + TDMFREE(pInterSql); return TSDB_CODE_TSC_OUT_OF_MEMORY; } extractTableName(pTableMetaInfo->name, param->buf); @@ -738,7 +738,7 @@ static int32_t tscProcessCurrentUser(SSqlObj *pSql) { STR_WITH_MAXSIZE_TO_VARSTR(vx, pSql->pTscObj->user, size); tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes); - free(vx); + TDMFREE(vx); return TSDB_CODE_SUCCESS; } @@ -767,7 +767,7 @@ static int32_t tscProcessCurrentDB(SSqlObj *pSql) { } tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes); - free(vx); + TDMFREE(vx); return TSDB_CODE_SUCCESS; } @@ -791,7 +791,7 @@ static int32_t tscProcessServerVer(SSqlObj *pSql) { STR_WITH_SIZE_TO_VARSTR(vx, v, (VarDataLenT)t); tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes); - free(vx); + TDMFREE(vx); return TSDB_CODE_SUCCESS; } @@ -814,7 +814,7 @@ static int32_t tscProcessClientVer(SSqlObj *pSql) { STR_WITH_SIZE_TO_VARSTR(v, version, (VarDataLenT)t); tscSetLocalQueryResult(pSql, v, pExpr->aliasName, pExpr->resType, pExpr->resBytes); - free(v); + TDMFREE(v); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index 921aa9bade..68fd1c300b 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -124,7 +124,7 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalReducer *pReducer, tOrderDesc } if (n == 0 || pCtx == NULL) { - free(pTagCtx); + TDMFREE(pTagCtx); } else { pCtx->tagInfo.pTagCtxList = pTagCtx; pCtx->tagInfo.numOfTagCols = n; @@ -242,7 +242,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd if (ds == NULL) { tscError("%p failed to create merge structure", pSql); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - tfree(pReducer); + TDMFREE(pReducer); return; } @@ -269,7 +269,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd if (ds->filePage.num == 0) { // no data in this flush, the index does not increase tscDebug("%p flush data is empty, ignore %d flush record", pSql, idx); - tfree(ds); + TDMFREE(ds); continue; } @@ -279,7 +279,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd // no data actually, no need to merge result. if (idx == 0) { - tfree(pReducer); + TDMFREE(pReducer); return; } @@ -287,7 +287,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd SCompareParam *param = malloc(sizeof(SCompareParam)); if (param == NULL) { - tfree(pReducer); + TDMFREE(pReducer); return; } @@ -301,8 +301,8 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pRes->code = tLoserTreeCreate(&pReducer->pLoserTree, pReducer->numOfBuffer, param, treeComparator); if (pReducer->pLoserTree == NULL || pRes->code != 0) { - tfree(param); - tfree(pReducer); + TDMFREE(param); + TDMFREE(pReducer); return; } @@ -344,14 +344,14 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd if (pReducer->pTempBuffer == NULL || pReducer->discardData == NULL || pReducer->pResultBuf == NULL || pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) { - tfree(pReducer->pTempBuffer); - tfree(pReducer->discardData); - tfree(pReducer->pResultBuf); - tfree(pReducer->pFinalRes); - tfree(pReducer->prevRowOfInput); - tfree(pReducer->pLoserTree); - tfree(param); - tfree(pReducer); + TDMFREE(pReducer->pTempBuffer); + TDMFREE(pReducer->discardData); + TDMFREE(pReducer->pResultBuf); + TDMFREE(pReducer->pFinalRes); + TDMFREE(pReducer->prevRowOfInput); + TDMFREE(pReducer->pLoserTree); + TDMFREE(param); + TDMFREE(pReducer); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; } @@ -501,38 +501,38 @@ void tscDestroyLocalReducer(SSqlObj *pSql) { SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[i]; tVariantDestroy(&pCtx->tag); - tfree(pCtx->resultInfo); + TDMFREE(pCtx->resultInfo); if (pCtx->tagInfo.pTagCtxList != NULL) { - tfree(pCtx->tagInfo.pTagCtxList); + TDMFREE(pCtx->tagInfo.pTagCtxList); } } - tfree(pLocalReducer->pCtx); + TDMFREE(pLocalReducer->pCtx); } - tfree(pLocalReducer->prevRowOfInput); + TDMFREE(pLocalReducer->prevRowOfInput); - tfree(pLocalReducer->pTempBuffer); - tfree(pLocalReducer->pResultBuf); + TDMFREE(pLocalReducer->pTempBuffer); + TDMFREE(pLocalReducer->pResultBuf); if (pLocalReducer->pLoserTree) { - tfree(pLocalReducer->pLoserTree->param); - tfree(pLocalReducer->pLoserTree); + TDMFREE(pLocalReducer->pLoserTree->param); + TDMFREE(pLocalReducer->pLoserTree); } - tfree(pLocalReducer->pFinalRes); - tfree(pLocalReducer->discardData); + TDMFREE(pLocalReducer->pFinalRes); + TDMFREE(pLocalReducer->discardData); tscLocalReducerEnvDestroy(pLocalReducer->pExtMemBuffer, pLocalReducer->pDesc, pLocalReducer->resColModel, pLocalReducer->finalModel, pLocalReducer->numOfVnode); for (int32_t i = 0; i < pLocalReducer->numOfBuffer; ++i) { - tfree(pLocalReducer->pLocalDataSrc[i]); + TDMFREE(pLocalReducer->pLocalDataSrc[i]); } pLocalReducer->numOfBuffer = 0; pLocalReducer->numOfCompleted = 0; - free(pLocalReducer); + TDMFREE(pLocalReducer); } else { tscDebug("%p already freed or another free function is invoked", pSql); } @@ -595,7 +595,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm } *pOrderDesc = tOrderDesCreate(orderColIndexList, numOfGroupByCols, pModel, pQueryInfo->order.order); - tfree(orderColIndexList); + TDMFREE(orderColIndexList); if (*pOrderDesc == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -708,7 +708,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr if (createOrderDescriptor(pOrderDesc, pCmd, pModel) != TSDB_CODE_SUCCESS) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - tfree(pSchema); + TDMFREE(pSchema); return pRes->code; } @@ -769,7 +769,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr *pFFModel = createColumnModel(pSchema, (int32_t) size, capacity); - tfree(pSchema); + TDMFREE(pSchema); return TSDB_CODE_SUCCESS; } @@ -790,7 +790,7 @@ void tscLocalReducerEnvDestroy(tExtMemBuffer **pMemBuffer, tOrderDescriptor *pDe pMemBuffer[i] = destoryExtMemBuffer(pMemBuffer[i]); } - tfree(pMemBuffer); + TDMFREE(pMemBuffer); } /** @@ -1020,10 +1020,10 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO pBeforeFillData->num = 0; for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { - tfree(pResPages[i]); + TDMFREE(pResPages[i]); } - tfree(pResPages); + TDMFREE(pResPages); } static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) { @@ -1151,7 +1151,7 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo } } - free(buf); + TDMFREE(buf); } int32_t finalizeRes(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) { @@ -1658,8 +1658,8 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_ memcpy(pOutput->data, pbuf, (size_t)(pOutput->num * offset)); - tfree(pbuf); - tfree(arithSup.data); + TDMFREE(pbuf); + TDMFREE(arithSup.data); return offset; } diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index ec90d21394..6341a56793 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -711,7 +711,7 @@ static int32_t doParseInsertStatement(SSqlCmd* pCmd, char **str, SParsedDataColI } int32_t numOfRows = tsParseValues(str, dataBuf, pTableMeta, maxNumOfRows, spd, pCmd, &code, tmpTokenBuf); - free(tmpTokenBuf); + TDMFREE(tmpTokenBuf); if (numOfRows <= 0) { return code; } @@ -946,7 +946,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { } kvRowCpy(pTag, row); - free(row); + TDMFREE(row); pCmd->tagData.data = pTag; index = 0; @@ -1337,10 +1337,10 @@ int tsParseSql(SSqlObj *pSql, bool initial) { char* sqlstr = strdup(pSql->sqlstr); ret = tsParseInsertSql(pSql); if (sqlstr == NULL || pSql->parseRetry >= 1 || ret != TSDB_CODE_TSC_INVALID_SQL) { - free(sqlstr); + TDMFREE(sqlstr); } else { tscResetSqlCmdObj(pCmd); - free(pSql->sqlstr); + TDMFREE(pSql->sqlstr); pSql->sqlstr = sqlstr; pSql->parseRetry++; if ((ret = tsInsertInitialCheck(pSql)) == TSDB_CODE_SUCCESS) { @@ -1425,7 +1425,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { } taos_free_result(pSql); - tfree(pSupporter); + TDMFREE(pSupporter); fclose(fp); pParentSql->res.code = code; @@ -1451,7 +1451,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { int32_t count = 0; int32_t maxRows = 0; - tfree(pCmd->pTableNameList); + TDMFREE(pCmd->pTableNameList); pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); if (pCmd->pTableBlockHashList == NULL) { @@ -1493,8 +1493,8 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { } } - tfree(tokenBuf); - free(line); + TDMFREE(tokenBuf); + TDMFREE(line); if (count > 0) { code = doPackSendDataBlock(pSql, count, pTableDataBlock); @@ -1506,7 +1506,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { } else { taos_free_result(pSql); - tfree(pSupporter); + TDMFREE(pSupporter); fclose(fp); pParentSql->fp = pParentSql->fetchFp; @@ -1534,7 +1534,7 @@ void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql) { pSql->res.code = TAOS_SYSTEM_ERROR(errno); tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code)); - tfree(pSupporter); + TDMFREE(pSupporter); tscAsyncResultOnError(pSql); return; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 8134a35811..7db195c131 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -860,7 +860,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { - free(pStmt); + TDMFREE(pStmt); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); return NULL; @@ -901,7 +901,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); - free(pCmd->payload); + TDMFREE(pCmd->payload); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -941,14 +941,14 @@ int taos_stmt_close(TAOS_STMT* stmt) { for (uint16_t i = 0; i < normal->numParams; i++) { tVariantDestroy(normal->params + i); } - free(normal->params); + TDMFREE(normal->params); } - free(normal->parts); - free(normal->sql); + TDMFREE(normal->parts); + TDMFREE(normal->sql); } taos_free_result(pStmt->pSql); - free(pStmt); + TDMFREE(pStmt); return TSDB_CODE_SUCCESS; } @@ -992,7 +992,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { } pStmt->pSql = taos_query((TAOS*)pStmt->taos, sql); ret = taos_errno(pStmt->pSql); - free(sql); + TDMFREE(sql); } } return ret; diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index f813ff85d9..935526f451 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -33,7 +33,7 @@ void tscInitConnCb(void *param, TAOS_RES *result, int code) { taos_close(tscSlowQueryConn); tscSlowQueryConn = NULL; tscSlowQueryConnInitialized = false; - free(sql); + TDMFREE(sql); } else { tscDebug("taos:%p, slow query connect success, code:%d", tscSlowQueryConn, code); tscSlowQueryConnInitialized = true; @@ -82,12 +82,12 @@ void tscSaveSlowQueryFp(void *handle, void *tmrId) { taos_connect_a(NULL, "monitor", tsInternalPass, "", 0, tscInitConnCb, sql, &tscSlowQueryConn); } else { tscError("taos:%p, slow query connect is already initialized", tscSlowQueryConn); - free(sql); + TDMFREE(sql); } } else { tscDebug("taos:%p, save slow query:%s", tscSlowQueryConn, sql); taos_query_a(tscSlowQueryConn, sql, tscSaveSlowQueryFpCb, NULL); - free(sql); + TDMFREE(sql); } } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4a5a7b09a2..ccb4687883 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4058,7 +4058,7 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t ret = setObjFullName(idBuf, account, &dbToken, &t, &xlen); if (ret != TSDB_CODE_SUCCESS) { taosStringBuilderDestroy(&sb1); - tfree(segments); + TDMFREE(segments); invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); return ret; @@ -4072,7 +4072,7 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, pQueryInfo->tagCond.tbnameCond.len = (int32_t) strlen(str); taosStringBuilderDestroy(&sb1); - tfree(segments); + TDMFREE(segments); return TSDB_CODE_SUCCESS; } @@ -6257,7 +6257,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { } kvRowCpy(pTag->data, row); - free(row); + TDMFREE(row); // table name if (tscValidateName(&(pCreateTableInfo->name)) != TSDB_CODE_SUCCESS) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 6314dc8c55..b785f741db 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -391,7 +391,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { memcpy(pRes->pRsp, rpcMsg->pCont, pRes->rspLen); } } else { - tfree(pRes->pRsp); + TDMFREE(pRes->pRsp); } /* @@ -747,7 +747,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->queryType = htonl(pQueryInfo->type); pQueryMsg->vgroupLimit = htobe64(pQueryInfo->vgroupLimit); pQueryMsg->sqlstrLen = htonl(sqlLen); - if(pSql->sqlstr && strlen(pSql->sqlstr) < sizeof((pQueryMsg->sqlstr)) { + if(pSql->sqlstr && strlen(pSql->sqlstr) < sizeof(pQueryMsg->sqlstr)) { strcpy(pQueryMsg->sqlstr, pSql->sqlstr); } @@ -1860,11 +1860,11 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { int32_t code = taosHashPut(tscTableMetaInfo, pTableMeta->sTableName, len, pSupTableMeta, size); assert(code == TSDB_CODE_SUCCESS); - tfree(pSupTableMeta); + TDMFREE(pSupTableMeta); CChildTableMeta* cMeta = tscCreateChildMeta(pTableMeta); taosHashPut(tscTableMetaInfo, pTableMetaInfo->name, strlen(pTableMetaInfo->name), cMeta, sizeof(CChildTableMeta)); - tfree(cMeta); + TDMFREE(cMeta); } else { uint32_t s = tscGetTableMetaSize(pTableMeta); taosHashPut(tscTableMetaInfo, pTableMetaInfo->name, strlen(pTableMetaInfo->name), pTableMeta, s); @@ -1887,7 +1887,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { } tscDebug("%p recv table meta, uid:%"PRId64 ", tid:%d, name:%s", pSql, pTableMeta->id.uid, pTableMeta->id.tid, pTableMetaInfo->name); - free(pTableMeta); + TDMFREE(pTableMeta); return TSDB_CODE_SUCCESS; } @@ -2079,7 +2079,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { pSchema++; } - tfree(pTableMetaInfo->pTableMeta); + TDMFREE(pTableMetaInfo->pTableMeta); pTableMetaInfo->pTableMeta = tscCreateTableMetaFromMsg(pMetaMsg); SSchema *pTableSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta); @@ -2121,7 +2121,7 @@ static void createHBObj(STscObj* pObj) { SQueryInfo *pQueryInfo = tscGetQueryInfoDetailSafely(&pSql->cmd, 0); if (pQueryInfo == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - tfree(pSql); + TDMFREE(pSql); return; } @@ -2130,7 +2130,7 @@ static void createHBObj(STscObj* pObj) { pSql->cmd.command = pQueryInfo->command; if (TSDB_CODE_SUCCESS != tscAllocPayload(&(pSql->cmd), TSDB_DEFAULT_PAYLOAD_SIZE)) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - tfree(pSql); + TDMFREE(pSql); return; } @@ -2213,7 +2213,7 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) { bool isSuperTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo); taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN)); - tfree(pTableMetaInfo->pTableMeta); + TDMFREE(pTableMetaInfo->pTableMeta); if (isSuperTable) { // if it is a super table, iterate the hashTable and remove all the childTableMeta taosHashEmpty(tscTableMetaInfo); @@ -2360,7 +2360,7 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { assert(strlen(pTableMetaInfo->name) != 0); - tfree(pTableMetaInfo->pTableMeta); + TDMFREE(pTableMetaInfo->pTableMeta); uint32_t size = tscGetTableMetaMaxSize(); pTableMetaInfo->pTableMeta = calloc(1, size); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 377cb24b1d..34ccb9d3ca 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -74,12 +74,12 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa char *base64 = (char *)base64_decode(auth, len, &outlen); if (base64 == NULL || outlen == 0) { tscError("invalid auth info:%s", auth); - free(base64); + TDMFREE(base64); terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH; return NULL; } else { memcpy(secretEncrypt, base64, outlen); - free(base64); + TDMFREE(base64); } secretEncryptLen = outlen; } @@ -108,8 +108,8 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa if (NULL == pObj->tscCorMgmtEpSet) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); - free(pObj->tscCorMgmtEpSet); - free(pObj); + TDMFREE(pObj->tscCorMgmtEpSet); + TDMFREE(pObj); } memcpy(pObj->tscCorMgmtEpSet, &corMgmtEpSet, sizeof(SRpcCorEpSet)); @@ -126,8 +126,8 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa if (len >= TSDB_DB_NAME_LEN) { terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH; rpcClose(pDnodeConn); - free(pObj->tscCorMgmtEpSet); - free(pObj); + TDMFREE(pObj->tscCorMgmtEpSet); + TDMFREE(pObj); return NULL; } @@ -144,8 +144,8 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa if (NULL == pSql) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); - free(pObj->tscCorMgmtEpSet); - free(pObj); + TDMFREE(pObj->tscCorMgmtEpSet); + TDMFREE(pObj); return NULL; } @@ -161,9 +161,9 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); - free(pSql); - free(pObj->tscCorMgmtEpSet); - free(pObj); + TDMFREE(pSql); + TDMFREE(pObj->tscCorMgmtEpSet); + TDMFREE(pObj); return NULL; } @@ -868,7 +868,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { int32_t sqlLen = (int32_t)strlen(sql); if (sqlLen > tsMaxSQLStringLen) { tscError("%p sql too long", pSql); - tfree(pSql); + TDMFREE(pSql); return TSDB_CODE_TSC_EXCEED_SQL_LIMIT; } @@ -876,7 +876,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { 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); - tfree(pSql); + TDMFREE(pSql); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1035,7 +1035,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { * to free connection, which may cause segment fault, when the parse phrase is not even successfully executed. */ pRes->qhandle = 0; - free(str); + TDMFREE(str); if (code != TSDB_CODE_SUCCESS) { tscFreeSqlObj(pSql); diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index c1ed9b0ba0..adbe8e34bf 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -271,10 +271,10 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf tscDebug("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name, pStream->numOfRes); - tfree(pTableMetaInfo->pTableMeta); + TDMFREE(pTableMetaInfo->pTableMeta); tscFreeSqlResult(pSql); - tfree(pSql->pSubs); + TDMFREE(pSql->pSubs); pSql->subState.numOfSub = 0; pTableMetaInfo->vgroupList = tscVgroupInfoClear(pTableMetaInfo->vgroupList); tscSetNextLaunchTimer(pStream, pSql); @@ -592,7 +592,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p } else if (code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { tscError("%p open stream failed, sql:%s, code:%s", pSql, sqlstr, tstrerror(pRes->code)); tscFreeSqlObj(pSql); - free(pStream); + TDMFREE(pStream); return NULL; } @@ -622,6 +622,6 @@ void taos_close_stream(TAOS_STREAM *handle) { pStream->pSql = NULL; taos_free_result(pSql); - tfree(pStream); + TDMFREE(pStream); } } diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 7f0b174ad3..1ea47428ce 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -194,7 +194,7 @@ fail: if (pSub != NULL) { taosArrayDestroy(pSub->progress); tsem_destroy(&pSub->sem); - free(pSub); + TDMFREE(pSub); pSub = NULL; } @@ -598,5 +598,5 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { taosArrayDestroy(pSub->progress); tsem_destroy(&pSub->sem); memset(pSub, 0, sizeof(*pSub)); - free(pSub); + TDMFREE(pSub); } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 681291d0db..0068991825 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -255,9 +255,9 @@ static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) { pSupporter->pVgroupTables = NULL; } - tfree(pSupporter->pIdTagList); + TDMFREE(pSupporter->pIdTagList); tscTagCondRelease(&pSupporter->tagCond); - free(pSupporter); + TDMFREE(pSupporter); } /* @@ -308,7 +308,7 @@ static void filterVgroupTables(SQueryInfo* pQueryInfo, SArray* pVgroupTables) { assert(taosArrayGetSize(pVgroupTables) > 0); TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY); - tfree(list); + TDMFREE(list); } static SArray* buildVgroupTableByResult(SQueryInfo* pQueryInfo, SArray* pVgroupTables) { @@ -335,7 +335,7 @@ static SArray* buildVgroupTableByResult(SQueryInfo* pQueryInfo, SArray* pVgroupT taosArrayPush(pNew, &info); } - tfree(list); + TDMFREE(list); TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY); return pNew; @@ -1624,8 +1624,8 @@ static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs) { SRetrieveSupport* pSupport = pSub->param; - tfree(pSupport->localBuffer); - tfree(pSupport); + TDMFREE(pSupport->localBuffer); + TDMFREE(pSupport); taos_free_result(pSub); } @@ -1667,7 +1667,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { if (ret != 0) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscAsyncResultOnError(pSql); - tfree(pMemoryBuf); + TDMFREE(pMemoryBuf); return ret; } @@ -1676,7 +1676,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { tscDebug("%p retrieved query data from %d vnode(s)", pSql, pState->numOfSub); if (pSql->pSubs == NULL) { - tfree(pSql->pSubs); + TDMFREE(pSql->pSubs); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pFinalModel,pState->numOfSub); @@ -1701,7 +1701,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { trs->localBuffer = (tFilePage *)calloc(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)); - tfree(trs); + TDMFREE(trs); break; } @@ -1713,8 +1713,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { SSqlObj *pNew = tscCreateSTableSubquery(pSql, trs, NULL); if (pNew == NULL) { tscError("%p failed to malloc buffer for subObj, orderOfSub:%d, reason:%s", pSql, i, strerror(errno)); - tfree(trs->localBuffer); - tfree(trs); + TDMFREE(trs->localBuffer); + TDMFREE(trs); break; } @@ -1764,8 +1764,8 @@ static void tscFreeRetrieveSup(SSqlObj *pSql) { } tscDebug("%p start to free subquery supp obj:%p", pSql, trsupport); - tfree(trsupport->localBuffer); - tfree(trsupport); + TDMFREE(trsupport->localBuffer); + TDMFREE(trsupport); } static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfRows); @@ -2177,7 +2177,7 @@ static void doFreeInsertSupporter(SSqlObj* pSqlObj) { for(int32_t i = 0; i < pSqlObj->subState.numOfSub; ++i) { SSqlObj* pSql = pSqlObj->pSubs[i]; - tfree(pSql->param); + TDMFREE(pSql->param); } } @@ -2561,7 +2561,7 @@ TAOS_ROW doSetResultRowData(SSqlObj *pSql) { assert(pRes->row >= 0 && pRes->row <= pRes->numOfRows); if (pRes->row >= pRes->numOfRows) { // all the results has returned to invoker - tfree(pRes->tsrow); + TDMFREE(pRes->tsrow); return pRes->tsrow; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index dd0f248b85..3f623059bd 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -275,7 +275,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { tscInfo("charset:%s is not valid in locale, charset remains:%s", charset, tsCharset); } - free(charset); + TDMFREE(charset); } else { // it may be windows system tscInfo("charset remains:%s", tsCharset); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index a6e33778cd..b2ac5deb15 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -257,7 +257,7 @@ void tscClearInterpInfo(SQueryInfo* pQueryInfo) { } pQueryInfo->fillType = TSDB_FILL_NONE; - tfree(pQueryInfo->fillVal); + TDMFREE(pQueryInfo->fillVal); } int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { @@ -271,10 +271,10 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { // not enough memory if (pRes->tsrow == NULL || pRes->urow == NULL || pRes->length == NULL || (pRes->buffer == NULL && pRes->numOfCols > 0)) { - tfree(pRes->tsrow); - tfree(pRes->urow); - tfree(pRes->length); - tfree(pRes->buffer); + TDMFREE(pRes->tsrow); + TDMFREE(pRes->urow); + TDMFREE(pRes->length); + TDMFREE(pRes->buffer); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; @@ -354,25 +354,25 @@ void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo) { static void tscDestroyResPointerInfo(SSqlRes* pRes) { if (pRes->buffer != NULL) { // free all buffers containing the multibyte string for (int i = 0; i < pRes->numOfCols; i++) { - tfree(pRes->buffer[i]); + TDMFREE(pRes->buffer[i]); } pRes->numOfCols = 0; } - tfree(pRes->pRsp); + TDMFREE(pRes->pRsp); - tfree(pRes->tsrow); - tfree(pRes->length); - tfree(pRes->buffer); - tfree(pRes->urow); + TDMFREE(pRes->tsrow); + TDMFREE(pRes->length); + TDMFREE(pRes->buffer); + TDMFREE(pRes->urow); - tfree(pRes->pGroupRec); - tfree(pRes->pColumnIndex); + TDMFREE(pRes->pGroupRec); + TDMFREE(pRes->pColumnIndex); if (pRes->pArithSup != NULL) { - tfree(pRes->pArithSup->data); - tfree(pRes->pArithSup); + TDMFREE(pRes->pArithSup->data); + TDMFREE(pRes->pArithSup); } pRes->data = NULL; // pRes->data points to the buffer of pRsp, no need to free @@ -388,11 +388,11 @@ void tscFreeQueryInfo(SSqlCmd* pCmd) { freeQueryInfoImpl(pQueryInfo); clearAllTableMetaInfo(pQueryInfo); - tfree(pQueryInfo); + TDMFREE(pQueryInfo); } pCmd->numOfClause = 0; - tfree(pCmd->pQueryInfo); + TDMFREE(pCmd->pQueryInfo); } void tscResetSqlCmdObj(SSqlCmd* pCmd) { @@ -406,12 +406,12 @@ void tscResetSqlCmdObj(SSqlCmd* pCmd) { for(int32_t i = 0; i < pCmd->numOfTables; ++i) { if (pCmd->pTableNameList && pCmd->pTableNameList[i]) { - tfree(pCmd->pTableNameList[i]); + TDMFREE(pCmd->pTableNameList[i]); } } pCmd->numOfTables = 0; - tfree(pCmd->pTableNameList); + TDMFREE(pCmd->pTableNameList); pCmd->pTableBlockHashList = tscDestroyBlockHashTable(pCmd->pTableBlockHashList); pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); @@ -486,24 +486,24 @@ void tscFreeSqlObj(SSqlObj* pSql) { pSql->signature = NULL; pSql->fp = NULL; - tfree(pSql->sqlstr); + TDMFREE(pSql->sqlstr); - tfree(pSql->pSubs); + TDMFREE(pSql->pSubs); pSql->subState.numOfSub = 0; pSql->self = 0; tscFreeSqlResult(pSql); tscResetSqlCmdObj(pCmd); - tfree(pCmd->tagData.data); + TDMFREE(pCmd->tagData.data); pCmd->tagData.dataLen = 0; memset(pCmd->payload, 0, (size_t)pCmd->allocSize); - tfree(pCmd->payload); + TDMFREE(pCmd->payload); pCmd->allocSize = 0; tsem_destroy(&pSql->rspSem); - free(pSql); + TDMFREE(pSql); } void tscDestroyDataBlock(STableDataBlocks* pDataBlock) { @@ -511,15 +511,15 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock) { return; } - tfree(pDataBlock->pData); - tfree(pDataBlock->params); + TDMFREE(pDataBlock->pData); + TDMFREE(pDataBlock->params); // free the refcount for metermeta if (pDataBlock->pTableMeta != NULL) { - tfree(pDataBlock->pTableMeta); + TDMFREE(pDataBlock->pTableMeta); } - tfree(pDataBlock); + TDMFREE(pDataBlock); } SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, int16_t bytes, @@ -590,7 +590,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) { tstrncpy(pTableMetaInfo->name, pDataBlock->tableName, sizeof(pTableMetaInfo->name)); if (pTableMetaInfo->pTableMeta != NULL) { - tfree(pTableMetaInfo->pTableMeta); + TDMFREE(pTableMetaInfo->pTableMeta); } pTableMetaInfo->pTableMeta = tscTableMetaClone(pDataBlock->pTableMeta); @@ -647,7 +647,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff dataBuf->pData = calloc(1, dataBuf->nAllocSize); if (dataBuf->pData == NULL) { tscError("failed to allocated memory, reason:%s", strerror(errno)); - tfree(dataBuf); + TDMFREE(dataBuf); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -823,7 +823,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql) { taosHashCleanup(pVnodeDataBlockHashList); tscDestroyBlockArrayList(pVnodeDataBlockList); - tfree(dataBuf->pData); + TDMFREE(dataBuf->pData); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -884,11 +884,11 @@ void tscCloseTscObj(void *param) { pObj->pDnodeConn = NULL; } - tfree(pObj->tscCorMgmtEpSet); + TDMFREE(pObj->tscCorMgmtEpSet); pthread_mutex_destroy(&pObj->mutex); tscDebug("%p DB connection is closed, dnodeConn:%p", pObj, p); - tfree(pObj); + TDMFREE(pObj); } bool tscIsInsertData(char* sqlstr) { @@ -1039,16 +1039,16 @@ void tscFieldInfoClear(SFieldInfo* pFieldInfo) { SSqlFuncMsg* pFuncMsg = &pInfo->pArithExprInfo->base; for(int32_t j = 0; j < pFuncMsg->numOfParams; ++j) { if (pFuncMsg->arg[j].argType == TSDB_DATA_TYPE_BINARY) { - tfree(pFuncMsg->arg[j].argValue.pz); + TDMFREE(pFuncMsg->arg[j].argValue.pz); } } - tfree(pInfo->pArithExprInfo); + TDMFREE(pInfo->pArithExprInfo); } } taosArrayDestroy(pFieldInfo->internalField); - tfree(pFieldInfo->final); + TDMFREE(pFieldInfo->final); memset(pFieldInfo, 0, sizeof(SFieldInfo)); } @@ -1163,7 +1163,7 @@ void* sqlExprDestroy(SSqlExpr* pExpr) { tVariantDestroy(&pExpr->param[i]); } - tfree(pExpr); + TDMFREE(pExpr); return NULL; } @@ -1263,11 +1263,11 @@ SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) { static void destroyFilterInfo(SColumnFilterInfo* pFilterInfo, int32_t numOfFilters) { for(int32_t i = 0; i < numOfFilters; ++i) { if (pFilterInfo[i].filterstr) { - tfree(pFilterInfo[i].pz); + TDMFREE(pFilterInfo[i].pz); } } - tfree(pFilterInfo); + TDMFREE(pFilterInfo); } SColumn* tscColumnClone(const SColumn* src) { @@ -1287,7 +1287,7 @@ SColumn* tscColumnClone(const SColumn* src) { static void tscColumnDestroy(SColumn* pCol) { destroyFilterInfo(pCol->filterInfo, pCol->numOfFilters); - free(pCol); + TDMFREE(pCol); } void tscColumnListCopy(SArray* dst, const SArray* src, int16_t tableIndex) { @@ -1548,13 +1548,13 @@ int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) { } void tscTagCondRelease(STagCond* pTagCond) { - free(pTagCond->tbnameCond.cond); + TDMFREE(pTagCond->tbnameCond.cond); if (pTagCond->pCond != NULL) { size_t s = taosArrayGetSize(pTagCond->pCond); for (int32_t i = 0; i < s; ++i) { SCond* p = taosArrayGet(pTagCond->pCond, i); - tfree(p->cond); + TDMFREE(p->cond); } taosArrayDestroy(pTagCond->pCond); @@ -1734,7 +1734,7 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo) { pQueryInfo->tsBuf = tsBufDestroy(pQueryInfo->tsBuf); - tfree(pQueryInfo->fillVal); + TDMFREE(pQueryInfo->fillVal); } void tscClearSubqueryInfo(SSqlCmd* pCmd) { @@ -1754,7 +1754,7 @@ void tscFreeVgroupTableInfo(SArray* pVgroupTables) { SVgroupTableInfo* pInfo = taosArrayGet(pVgroupTables, i); for(int32_t j = 0; j < pInfo->vgInfo.numOfEps; ++j) { - tfree(pInfo->vgInfo.epAddr[j].fqdn); + TDMFREE(pInfo->vgInfo.epAddr[j].fqdn); } taosArrayDestroy(pInfo->itemList); @@ -1771,7 +1771,7 @@ void tscRemoveVgroupTableGroup(SArray* pVgroupTable, int32_t index) { SVgroupTableInfo* pInfo = taosArrayGet(pVgroupTable, index); for(int32_t j = 0; j < pInfo->vgInfo.numOfEps; ++j) { - tfree(pInfo->vgInfo.epAddr[j].fqdn); + TDMFREE(pInfo->vgInfo.epAddr[j].fqdn); } taosArrayDestroy(pInfo->itemList); @@ -1814,10 +1814,10 @@ void clearAllTableMetaInfo(SQueryInfo* pQueryInfo) { tscFreeVgroupTableInfo(pTableMetaInfo->pVgroupTables); tscClearTableMetaInfo(pTableMetaInfo); - free(pTableMetaInfo); + TDMFREE(pTableMetaInfo); } - tfree(pQueryInfo->pTableMetaInfo); + TDMFREE(pQueryInfo->pTableMetaInfo); } STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta, @@ -1872,7 +1872,7 @@ void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo) { return; } - tfree(pTableMetaInfo->pTableMeta); + TDMFREE(pTableMetaInfo->pTableMeta); pTableMetaInfo->vgroupList = tscVgroupInfoClear(pTableMetaInfo->vgroupList); tscColumnListDestroy(pTableMetaInfo->tagColList); @@ -1915,7 +1915,7 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cm int32_t code = copyTagData(&pNew->cmd.tagData, &pSql->cmd.tagData); if (code != TSDB_CODE_SUCCESS) { tscError("%p new subquery failed, unable to malloc tag data, tableIndex:%d", pSql, 0); - free(pNew); + TDMFREE(pNew); return NULL; } @@ -2411,7 +2411,7 @@ void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp) { pRes->numOfTotal = num; - tfree(pSql->pSubs); + TDMFREE(pSql->pSubs); pSql->subState.numOfSub = 0; pSql->fp = fp; @@ -2536,7 +2536,7 @@ void* tscVgroupInfoClear(SVgroupsInfo *vgroupList) { SVgroupInfo* pVgroupInfo = &vgroupList->vgroups[i]; for(int32_t j = 0; j < pVgroupInfo->numOfEps; ++j) { - tfree(pVgroupInfo->epAddr[j].fqdn); + TDMFREE(pVgroupInfo->epAddr[j].fqdn); } for(int32_t j = pVgroupInfo->numOfEps; j < TSDB_MAX_REPLICA; j++) { @@ -2544,7 +2544,7 @@ void* tscVgroupInfoClear(SVgroupsInfo *vgroupList) { } } - tfree(vgroupList); + TDMFREE(vgroupList); return NULL; } @@ -2552,7 +2552,7 @@ void tscSVgroupInfoCopy(SVgroupInfo* dst, const SVgroupInfo* src) { dst->vgId = src->vgId; dst->numOfEps = src->numOfEps; for(int32_t i = 0; i < dst->numOfEps; ++i) { - tfree(dst->epAddr[i].fqdn); + TDMFREE(dst->epAddr[i].fqdn); dst->epAddr[i].port = src->epAddr[i].port; assert(dst->epAddr[i].fqdn == NULL); @@ -2653,12 +2653,12 @@ int32_t tscCreateTableMetaFromCChildMeta(STableMeta* pChild, const char* name) { memcpy(pChild->schema, p->schema, sizeof(SSchema) *total); - tfree(p); + TDMFREE(p); return TSDB_CODE_SUCCESS; } else { // super table has been removed, current tableMeta is also expired. remove it here taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN)); - tfree(p); + TDMFREE(p); return -1; } } diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h index 439e4cab72..83bc33cac5 100644 --- a/src/os/inc/osMemory.h +++ b/src/os/inc/osMemory.h @@ -17,6 +17,7 @@ #define TDENGINE_OS_MEMORY_H #include "osString.h" +#include #ifdef __cplusplus extern "C" { @@ -81,6 +82,28 @@ void taosTMemset(void *ptr, int c); #endif #endif + +#define TDM_MAX_NUM 1000 + +extern int32_t tdm_num; +extern long tdm_ps; + +void tdmfree(void *p); + +void *tdmrealloc(void *p, int s); + +void *tdmalloc(char *f, unsigned line, int s,int set); +void tdminit(); + +#define TDMALLOCED(p) ((*(long *)(((void*)p)-8)==0x1234567887654321L) && (*(long *)(((void *)p)-16)==0x0011223344556677L)) +#define TDMSIZE(s) ((s+24)%tdm_ps == 0 ? (s+24)+tdm_ps:((s+24)/tdm_ps+2)*tdm_ps) + +#define TDMALLOC(s) tdmalloc(__FILE__, __LINE__, s,0) +#define TDMCALLOC(s) tdmalloc(__FILE__, __LINE__, s,1) +#define TDMREALLOC(p,s) tdmrealloc(p,s) +#define TDMFREE(p) tdmfree((void *)p) + + #ifdef __cplusplus } #endif diff --git a/src/os/src/detail/osMemory.c b/src/os/src/detail/osMemory.c index 53310d179c..4fe4fb85e7 100644 --- a/src/os/src/detail/osMemory.c +++ b/src/os/src/detail/osMemory.c @@ -516,4 +516,122 @@ void taosTZfree(void *ptr) { if (ptr) { free((void *)((char *)ptr - sizeof(size_t))); } -} \ No newline at end of file +} + + +int32_t tdm_num = 0; +long tdm_ps; +typedef struct{ + uint64_t normalfn; + uint64_t tdmfn; + uint64_t normalmn; + uint64_t tdmmn; + uint64_t normalrn; + uint64_t tdmrn; +}tdmstat; + +tdmstat tdm_stat; + +void tdminit(){ + tdm_ps = sysconf(_SC_PAGE_SIZE); + + srand(time(NULL)); + + memset(&tdm_stat, 0, sizeof(tdm_stat)); +} + +void *tdmrealloc(void *p, int s){ + if(p && TDMALLOCED(p)){ + atomic_add_fetch_64(&tdm_stat.tdmrn, 1); + void *lp = *(void **)((long)p-24); + int os=(long)lp - (long)p; + if(s= TDM_MAX_NUM || rand()%10!=0){ + atomic_add_fetch_64(&tdm_stat.normalmn, 1); + if(set){ + p=calloc(s,1); + }else{ + p=malloc(s); + } + + //printf("direct malloc:%p,size:%d\n", p, s); + assert(p); + return p; + } + + + atomic_add_fetch_64(&tdm_stat.tdmmn, 1); + + int ns = TDMSIZE(s); + void *buffer = memalign(tdm_ps, ns); + if (buffer == NULL){ + assert(0); + } + + if(set){ + memset(buffer,0,ns); + } + + void *lastp = buffer + ns - tdm_ps; + + *(long *)(lastp-s-8)=0x1234567887654321L; + *(long *)(lastp-s-16)=0x0011223344556677L; + *(void **)(lastp-s-24)=buffer + ns - tdm_ps; + + sprintf(lastp,"%s:%d,len:%d",f,line,s); + *(char *)(lastp+strlen(lastp))=0; + *(long *)(lastp+strlen(lastp)+1)=0x1234567887654321L; + + + if (mprotect(buffer + ns - tdm_ps, tdm_ps,PROT_READ) == -1){ + assert(0); + } + + atomic_add_fetch_32(&tdm_num, 1); + + //printf("os:%d,ns:%d,realb:%p,retb:%p,lpd:%p,tdm_num:%d\n", s, ns, buffer, lastp-s, buffer+ns-tdm_ps, tdm_num); + + return lastp - s; +} + +void tdmfree(void *p){ + + if(p && TDMALLOCED(p)){ + atomic_add_fetch_64(&tdm_stat.tdmfn, 1); + void * fp = (void *)((0xfffffffffffff000 | tdm_ps) & ((long)p-24)); + //printf("tdmfree realb:%p,retb:%p,lpd:%p\n", fp,p, *(void **)((long)p-24)); + mprotect(*(void **)((long)p-24), tdm_ps,PROT_WRITE|PROT_READ); + atomic_sub_fetch_32(&tdm_num, 1); + memset((void *)((long)p-24), 0, 24); + free(fp); + fp=0; + }else{ + //printf("direct free %p\n", p); + atomic_add_fetch_64(&tdm_stat.normalfn, 1); + free(p); + p=0; + } +} + + + + diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 2997d56326..bbf99bf49f 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -2044,7 +2044,7 @@ static void copyTopBotRes(SQLFunctionCtx *pCtx, int32_t type) { } } - tfree(pData); + TDMFREE(pData); } /* @@ -2597,7 +2597,7 @@ static void apercentile_finalizer(SQLFunctionCtx *pCtx) { double *res = tHistogramUniform(pOutput->pHisto, ratio, 1); memcpy(pCtx->aOutputBuf, res, sizeof(double)); - free(res); + TDMFREE(res); } else { setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes); return; @@ -2608,7 +2608,7 @@ static void apercentile_finalizer(SQLFunctionCtx *pCtx) { double *res = tHistogramUniform(pOutput->pHisto, ratio, 1); memcpy(pCtx->aOutputBuf, res, sizeof(double)); - free(res); + TDMFREE(res); } else { // no need to free setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes); return; diff --git a/src/query/src/qAst.c b/src/query/src/qAst.c index c23a794196..746de0fba8 100644 --- a/src/query/src/qAst.c +++ b/src/query/src/qAst.c @@ -112,10 +112,10 @@ void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)) { } else if (pNode->nodeType == TSQL_NODE_VALUE) { tVariantDestroy(pNode->pVal); } else if (pNode->nodeType == TSQL_NODE_COL) { - free(pNode->pSchema); + TDMFREE(pNode->pSchema); } - free(pNode); + TDMFREE(pNode); } void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) { @@ -132,12 +132,12 @@ void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) { } } else if ((*pExpr)->nodeType == TSQL_NODE_VALUE) { tVariantDestroy((*pExpr)->pVal); - free((*pExpr)->pVal); + TDMFREE((*pExpr)->pVal); } else if ((*pExpr)->nodeType == TSQL_NODE_COL) { - free((*pExpr)->pSchema); + TDMFREE((*pExpr)->pSchema); } - free(*pExpr); + TDMFREE(*pExpr); *pExpr = NULL; } @@ -270,8 +270,8 @@ void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, } } - free(pLeftOutput); - free(pRightOutput); + TDMFREE(pLeftOutput); + TDMFREE(pRightOutput); } static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 295675d719..feba941b81 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1863,7 +1863,7 @@ static int32_t setCtxTagColumnInfo(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx p->tagInfo.numOfTagCols = num; p->tagInfo.tagsLen = tagLen; } else { - tfree(pTagCtx); + TDMFREE(pTagCtx); } } @@ -1984,10 +1984,10 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order return TSDB_CODE_SUCCESS; _clean: - tfree(pRuntimeEnv->pCtx); - tfree(pRuntimeEnv->offset); - tfree(pRuntimeEnv->rowCellInfoOffset); - tfree(pRuntimeEnv->sasArray); + TDMFREE(pRuntimeEnv->pCtx); + TDMFREE(pRuntimeEnv->offset); + TDMFREE(pRuntimeEnv->rowCellInfoOffset); + TDMFREE(pRuntimeEnv->sasArray); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -2025,18 +2025,18 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { } tVariantDestroy(&pCtx->tag); - tfree(pCtx->tagInfo.pTagCtxList); + TDMFREE(pCtx->tagInfo.pTagCtxList); } - tfree(pRuntimeEnv->pCtx); + TDMFREE(pRuntimeEnv->pCtx); } if (pRuntimeEnv->sasArray != NULL) { for(int32_t i = 0; i < pQuery->numOfOutput; ++i) { - tfree(pRuntimeEnv->sasArray[i].data); + TDMFREE(pRuntimeEnv->sasArray[i].data); } - tfree(pRuntimeEnv->sasArray); + TDMFREE(pRuntimeEnv->sasArray); } pRuntimeEnv->pFillInfo = taosDestroyFillInfo(pRuntimeEnv->pFillInfo); @@ -2046,10 +2046,10 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { pRuntimeEnv->pTsBuf = tsBufDestroy(pRuntimeEnv->pTsBuf); - tfree(pRuntimeEnv->offset); - tfree(pRuntimeEnv->keyBuf); - tfree(pRuntimeEnv->rowCellInfoOffset); - tfree(pRuntimeEnv->prevRow); + TDMFREE(pRuntimeEnv->offset); + TDMFREE(pRuntimeEnv->keyBuf); + TDMFREE(pRuntimeEnv->rowCellInfoOffset); + TDMFREE(pRuntimeEnv->prevRow); taosHashCleanup(pRuntimeEnv->pResultRowHashTable); pRuntimeEnv->pResultRowHashTable = NULL; @@ -3297,9 +3297,9 @@ int32_t mergeIntoGroupResultImpl(SGroupResInfo* pGroupResInfo, SArray *pTableLis qDebug("QInfo:%p result merge completed for group:%d, elapsed time:%" PRId64 " ms", pQInfo, pQInfo->groupIndex, endt - startt); _end: - tfree(pTableQueryInfoList); - tfree(posList); - tfree(pTree); + TDMFREE(pTableQueryInfoList); + TDMFREE(posList); + TDMFREE(pTree); return code; } @@ -5605,11 +5605,11 @@ static void doSecondaryArithmeticProcess(SQuery* pQuery) { } for (int32_t i = 0; i < pQuery->numOfExpr2; ++i) { - tfree(data[i]); + TDMFREE(data[i]); } - tfree(data); - tfree(arithSup.data); + TDMFREE(data); + TDMFREE(arithSup.data); } /* @@ -6231,14 +6231,14 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, return TSDB_CODE_SUCCESS; _cleanup: - tfree(*pExpr); + TDMFREE(*pExpr); taosArrayDestroy(*pTableIdList); *pTableIdList = NULL; - tfree(*tbnameCond); - tfree(*groupbyCols); - tfree(*tagCols); - tfree(*tagCond); - tfree(*sql); + TDMFREE(*tbnameCond); + TDMFREE(*groupbyCols); + TDMFREE(*tagCols); + TDMFREE(*tagCond); + TDMFREE(*sql); return code; } @@ -6289,7 +6289,7 @@ static int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t num code = buildArithmeticExprFromMsg(&pExprs[i], pQueryMsg); if (code != TSDB_CODE_SUCCESS) { - tfree(pExprs); + TDMFREE(pExprs); return code; } @@ -6336,7 +6336,7 @@ static int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t num int32_t param = (int32_t)pExprs[i].base.arg[0].argValue.i64; if (getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].type, &pExprs[i].bytes, &pExprs[i].interBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) { - tfree(pExprs); + TDMFREE(pExprs); return TSDB_CODE_QRY_INVALID_MSG; } @@ -6734,10 +6734,10 @@ _cleanup_qinfo: _cleanup_query: if (pGroupbyExpr != NULL) { taosArrayDestroy(pGroupbyExpr->columnInfo); - free(pGroupbyExpr); + TDMFREE(pGroupbyExpr); } - tfree(pTagCols); + TDMFREE(pTagCols); for (int32_t i = 0; i < numOfOutput; ++i) { SExprInfo* pExprInfo = &pExprs[i]; if (pExprInfo->pExpr != NULL) { @@ -6745,7 +6745,7 @@ _cleanup_query: } } - tfree(pExprs); + TDMFREE(pExprs); _cleanup: freeQInfo(pQInfo); @@ -6820,11 +6820,11 @@ static void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilter for (int32_t i = 0; i < numOfFilters; i++) { if (pFilter[i].filterstr) { - free((void*)(pFilter[i].pz)); + TDMFREE((void*)(pFilter[i].pz)); } } - free(pFilter); + TDMFREE(pFilter); } static void doDestroyTableQueryInfo(STableGroupInfo* pTableqinfoGroupInfo) { @@ -6863,7 +6863,7 @@ static void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr) { } } - tfree(pExprInfo); + TDMFREE(pExprInfo); return NULL; } @@ -6882,48 +6882,48 @@ static void freeQInfo(SQInfo *pQInfo) { if (pQuery != NULL) { if (pQuery->sdata != NULL) { for (int32_t col = 0; col < pQuery->numOfOutput; ++col) { - tfree(pQuery->sdata[col]); + TDMFREE(pQuery->sdata[col]); } - tfree(pQuery->sdata); + TDMFREE(pQuery->sdata); } if (pQuery->fillVal != NULL) { - tfree(pQuery->fillVal); + TDMFREE(pQuery->fillVal); } for (int32_t i = 0; i < pQuery->numOfFilterCols; ++i) { SSingleColumnFilterInfo *pColFilter = &pQuery->pFilterInfo[i]; if (pColFilter->numOfFilters > 0) { - tfree(pColFilter->pFilters); + TDMFREE(pColFilter->pFilters); } } pQuery->pExpr1 = destroyQueryFuncExpr(pQuery->pExpr1, pQuery->numOfOutput); pQuery->pExpr2 = destroyQueryFuncExpr(pQuery->pExpr2, pQuery->numOfExpr2); - tfree(pQuery->tagColList); - tfree(pQuery->pFilterInfo); + TDMFREE(pQuery->tagColList); + TDMFREE(pQuery->pFilterInfo); if (pQuery->colList != NULL) { for (int32_t i = 0; i < pQuery->numOfCols; i++) { SColumnInfo *column = pQuery->colList + i; freeColumnFilterInfo(column->filters, column->numOfFilters); } - tfree(pQuery->colList); + TDMFREE(pQuery->colList); } if (pQuery->pGroupbyExpr != NULL) { taosArrayDestroy(pQuery->pGroupbyExpr->columnInfo); - tfree(pQuery->pGroupbyExpr); + TDMFREE(pQuery->pGroupbyExpr); } - tfree(pQuery); + TDMFREE(pQuery); } doDestroyTableQueryInfo(&pQInfo->tableqinfoGroupInfo); - tfree(pQInfo->pBuf); - tfree(pQInfo->sql); + TDMFREE(pQInfo->pBuf); + TDMFREE(pQInfo->sql); tsdbDestroyTableGroup(&pQInfo->tableGroupInfo); taosHashCleanup(pQInfo->arrTableIdInfo); @@ -6934,7 +6934,7 @@ static void freeQInfo(SQInfo *pQInfo) { qDebug("QInfo:%p QInfo is freed", pQInfo); - tfree(pQInfo); + TDMFREE(pQInfo); } static size_t getResultSize(SQInfo *pQInfo, int64_t *numOfRows) { @@ -7136,22 +7136,22 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi code = initQInfo(pQueryMsg, tsdb, vgId, *pQInfo, isSTableQuery); _over: - free(tagCond); - free(tbnameCond); - free(pGroupColIndex); + TDMFREE(tagCond); + TDMFREE(tbnameCond); + TDMFREE(pGroupColIndex); if (pGroupbyExpr != NULL) { taosArrayDestroy(pGroupbyExpr->columnInfo); - free(pGroupbyExpr); + TDMFREE(pGroupbyExpr); } - free(pTagColumnInfo); - free(sql); - free(pExprs); - free(pSecExprs); + TDMFREE(pTagColumnInfo); + TDMFREE(sql); + TDMFREE(pExprs); + TDMFREE(pSecExprs); - free(pExprMsg); - free(pSecExprMsg); + TDMFREE(pExprMsg); + TDMFREE(pSecExprMsg); taosArrayDestroy(pTableIdList); @@ -7652,7 +7652,7 @@ void qCleanupQueryMgmt(void* pQMgmt) { taosCacheCleanup(pqinfoPool); pthread_mutex_destroy(&pQueryMgmt->lock); - tfree(pQueryMgmt); + TDMFREE(pQueryMgmt); qDebug("vgId:%d, queryMgmt cleanup completed", vgId); } diff --git a/src/query/src/qExtbuffer.c b/src/query/src/qExtbuffer.c index fa3fe285a8..1393706df0 100644 --- a/src/query/src/qExtbuffer.c +++ b/src/query/src/qExtbuffer.c @@ -64,7 +64,7 @@ void* destoryExtMemBuffer(tExtMemBuffer *pMemBuffer) { // release flush out info link SExtFileInfo *pFileMeta = &pMemBuffer->fileMeta; if (pFileMeta->flushoutData.nAllocSize != 0 && pFileMeta->flushoutData.pFlushoutInfo != NULL) { - tfree(pFileMeta->flushoutData.pFlushoutInfo); + TDMFREE(pFileMeta->flushoutData.pFlushoutInfo); } // release all in-memory buffer pages @@ -72,7 +72,7 @@ void* destoryExtMemBuffer(tExtMemBuffer *pMemBuffer) { while (pFilePages != NULL) { tFilePagesItem *pTmp = pFilePages; pFilePages = pFilePages->pNext; - tfree(pTmp); + TDMFREE(pTmp); } // close temp file @@ -87,8 +87,8 @@ void* destoryExtMemBuffer(tExtMemBuffer *pMemBuffer) { destroyColumnModel(pMemBuffer->pColumnModel); - tfree(pMemBuffer->path); - tfree(pMemBuffer); + TDMFREE(pMemBuffer->path); + TDMFREE(pMemBuffer); return NULL; } @@ -275,7 +275,7 @@ int32_t tExtMemBufferFlush(tExtMemBuffer *pMemBuffer) { tFilePagesItem *ptmp = first; first = first->pNext; - tfree(ptmp); // release all data in memory buffer + TDMFREE(ptmp); // release all data in memory buffer } fflush(pMemBuffer->file); // flush to disk @@ -300,7 +300,7 @@ void tExtMemBufferClear(tExtMemBuffer *pMemBuffer) { while (first != NULL) { tFilePagesItem *ptmp = first; first = first->pNext; - tfree(ptmp); + TDMFREE(ptmp); } pMemBuffer->fileMeta.numOfElemsInFile = 0; @@ -751,7 +751,7 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta columnwiseQSortImpl(pDescriptor, numOfRows, start, end, data, order, compareFn, buf); } - free(buf); + TDMFREE(buf); } /* @@ -802,7 +802,7 @@ void destroyColumnModel(SColumnModel *pModel) { return; } - tfree(pModel); + TDMFREE(pModel); } static void printBinaryData(char *data, int32_t len) { @@ -1087,5 +1087,5 @@ void tOrderDescDestroy(tOrderDescriptor *pDesc) { } destroyColumnModel(pDesc->pColumnModel); - tfree(pDesc); + TDMFREE(pDesc); } diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index ca1203cb17..72c0aa894c 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -121,18 +121,18 @@ void* taosDestroyFillInfo(SFillInfo* pFillInfo) { return NULL; } - tfree(pFillInfo->prevValues); - tfree(pFillInfo->nextValues); - tfree(pFillInfo->pTags); + TDMFREE(pFillInfo->prevValues); + TDMFREE(pFillInfo->nextValues); + TDMFREE(pFillInfo->pTags); for(int32_t i = 0; i < pFillInfo->numOfCols; ++i) { - tfree(pFillInfo->pData[i]); + TDMFREE(pFillInfo->pData[i]); } - tfree(pFillInfo->pData); - tfree(pFillInfo->pFillCol); + TDMFREE(pFillInfo->pData); + TDMFREE(pFillInfo->pFillCol); - tfree(pFillInfo); + TDMFREE(pFillInfo); return NULL; } @@ -457,7 +457,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t ou if (pFillInfo->index >= pFillInfo->numOfRows || pFillInfo->numOfCurrent >= outputRows) { /* the raw data block is exhausted, next value does not exists */ if (pFillInfo->index >= pFillInfo->numOfRows) { - tfree(*next); + TDMFREE(*next); } pFillInfo->numOfTotal += pFillInfo->numOfCurrent; diff --git a/src/query/src/qHistogram.c b/src/query/src/qHistogram.c index 0d31948e59..2d3981461f 100644 --- a/src/query/src/qHistogram.c +++ b/src/query/src/qHistogram.c @@ -438,7 +438,7 @@ void tHistogramDestroy(SHistogramInfo** pHisto) { return; } - free(*pHisto); + TDMFREE(*pHisto); *pHisto = NULL; } @@ -659,6 +659,6 @@ SHistogramInfo* tHistogramMerge(SHistogramInfo* pHisto1, SHistogramInfo* pHisto2 pResHistogram->numOfEntries = k; memcpy(pResHistogram->elems, pHistoBins, sizeof(SHistBin) * k); - free(pHistoBins); + TDMFREE(pHistoBins); return pResHistogram; } diff --git a/src/query/src/qParserImpl.c b/src/query/src/qParserImpl.c index 4b3a56e4ee..e3ea161802 100644 --- a/src/query/src/qParserImpl.c +++ b/src/query/src/qParserImpl.c @@ -67,7 +67,7 @@ SSqlInfo qSQLParse(const char *pStr) { } abort_parse: - ParseFree(pParser, free); + ParseFree(pParser, tdmfree); return sqlInfo; } @@ -106,13 +106,13 @@ void tSqlExprListDestroy(tSQLExprList *pList) { for (int32_t i = 0; i < pList->nExpr; ++i) { if (pList->a[i].aliasName != NULL) { - free(pList->a[i].aliasName); + TDMFREE(pList->a[i].aliasName); } tSqlExprDestroy(pList->a[i].pNode); } - free(pList->a); - free(pList); + TDMFREE(pList->a); + TDMFREE(pList); } tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) { @@ -299,7 +299,7 @@ void tSqlExprNodeDestroy(tSQLExpr *pExpr) { tSqlExprListDestroy(pExpr->pParam); - free(pExpr); + TDMFREE(pExpr); } void tSqlExprDestroy(tSQLExpr *pExpr) { @@ -487,8 +487,8 @@ static void freeVariant(void *pItem) { void freeCreateTableInfo(void* p) { SCreatedTableInfo* pInfo = (SCreatedTableInfo*) p; taosArrayDestroyEx(pInfo->pTagVals, freeVariant); - tfree(pInfo->fullname); - tfree(pInfo->tagdata.data); + TDMFREE(pInfo->fullname); + TDMFREE(pInfo->tagdata.data); } void doDestroyQuerySql(SQuerySQL *pQuerySql) { @@ -515,7 +515,7 @@ void doDestroyQuerySql(SQuerySQL *pQuerySql) { taosArrayDestroyEx(pQuerySql->fillType, freeVariant); pQuerySql->fillType = NULL; - free(pQuerySql); + TDMFREE(pQuerySql); } void destroyAllSelectClause(SSubclauseInfo *pClause) { @@ -528,7 +528,7 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) { doDestroyQuerySql(pQuerySql); } - tfree(pClause->pClause); + TDMFREE(pClause->pClause); } SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSelect, int32_t type) { @@ -603,7 +603,7 @@ void* destroyCreateTableSql(SCreateTableSQL* pCreate) { taosArrayDestroy(pCreate->colInfo.pTagColumns); taosArrayDestroyEx(pCreate->childTableInfo, freeCreateTableInfo); - tfree(pCreate); + TDMFREE(pCreate); return NULL; } @@ -618,18 +618,18 @@ void SqlInfoDestroy(SSqlInfo *pInfo) { } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) { taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeVariant); taosArrayDestroy(pInfo->pAlterInfo->pAddColumns); - tfree(pInfo->pAlterInfo->tagData.data); - tfree(pInfo->pAlterInfo); + TDMFREE(pInfo->pAlterInfo->tagData.data); + TDMFREE(pInfo->pAlterInfo); } else { if (pInfo->pDCLInfo != NULL && pInfo->pDCLInfo->nAlloc > 0) { - free(pInfo->pDCLInfo->a); + TDMFREE(pInfo->pDCLInfo->a); } if (pInfo->pDCLInfo != NULL && pInfo->type == TSDB_SQL_CREATE_DB) { taosArrayDestroyEx(pInfo->pDCLInfo->dbOpt.keep, freeVariant); } - tfree(pInfo->pDCLInfo); + TDMFREE(pInfo->pDCLInfo); } } @@ -657,7 +657,7 @@ SSqlInfo*setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pTableName, if (type == TSDB_SQL_SELECT) { pInfo->subclauseInfo = *(SSubclauseInfo*) pSqlExprInfo; - free(pSqlExprInfo); + TDMFREE(pSqlExprInfo); } else { pInfo->pCreateTableInfo = pSqlExprInfo; } diff --git a/src/query/src/qPercentile.c b/src/query/src/qPercentile.c index 51125d62b9..9c7f798a3a 100644 --- a/src/query/src/qPercentile.c +++ b/src/query/src/qPercentile.c @@ -329,7 +329,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, if (setBoundingBox(&pBucket->range, pBucket->type, minval, maxval) != 0) { uError("MemBucket:%p, invalid value range: %f-%f", pBucket, minval, maxval); - free(pBucket); + TDMFREE(pBucket); return NULL; } @@ -339,13 +339,13 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, pBucket->hashFunc = getHashFunc(pBucket->type); if (pBucket->hashFunc == NULL) { uError("MemBucket:%p, not support data type %d, failed", pBucket, pBucket->type); - free(pBucket); + TDMFREE(pBucket); return NULL; } pBucket->pSlots = (tMemBucketSlot *)calloc(pBucket->numOfSlots, sizeof(tMemBucketSlot)); if (pBucket->pSlots == NULL) { - free(pBucket); + TDMFREE(pBucket); return NULL; } @@ -367,8 +367,8 @@ void tMemBucketDestroy(tMemBucket *pBucket) { } destroyResultBuf(pBucket->pBuffer); - tfree(pBucket->pSlots); - tfree(pBucket); + TDMFREE(pBucket->pSlots); + TDMFREE(pBucket); } void tMemBucketUpdateBoundingBox(MinMaxEntry *r, const char *data, int32_t dataType) { @@ -686,7 +686,7 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) } double val = (1 - fraction) * td + fraction * nd; - tfree(buffer); + TDMFREE(buffer); return val; } else { // incur a second round bucket split diff --git a/src/query/src/qResultbuf.c b/src/query/src/qResultbuf.c index d45e76c2fd..133879c6e2 100644 --- a/src/query/src/qResultbuf.c +++ b/src/query/src/qResultbuf.c @@ -270,7 +270,7 @@ static char* evicOneDataPage(SDiskbasedResultBuf* pResultBuf) { assert(d->pn == pn); d->pn = NULL; - tfree(pn); + TDMFREE(pn); bufPage = flushPageToDisk(pResultBuf, d); } @@ -421,15 +421,15 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) { } unlink(pResultBuf->path); - tfree(pResultBuf->path); + TDMFREE(pResultBuf->path); SArray** p = taosHashIterate(pResultBuf->groupSet, NULL); while(p) { size_t n = taosArrayGetSize(*p); for(int32_t i = 0; i < n; ++i) { SPageInfo* pi = taosArrayGetP(*p, i); - tfree(pi->pData); - tfree(pi); + TDMFREE(pi->pData); + TDMFREE(pi); } taosArrayDestroy(*p); @@ -441,8 +441,8 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) { taosHashCleanup(pResultBuf->groupSet); taosHashCleanup(pResultBuf->all); - tfree(pResultBuf->assistBuf); - tfree(pResultBuf); + TDMFREE(pResultBuf->assistBuf); + TDMFREE(pResultBuf); } SPageInfo* getLastPageInfo(SIDList pList) { diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index d0c59fe5ef..14e6767f85 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -23,7 +23,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { taosGetTmpfilePath("join", pTSBuf->path); pTSBuf->f = fopen(pTSBuf->path, "w+"); if (pTSBuf->f == NULL) { - free(pTSBuf); + TDMFREE(pTSBuf); return NULL; } @@ -54,7 +54,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { pTSBuf->f = fopen(pTSBuf->path, "r+"); if (pTSBuf->f == NULL) { - free(pTSBuf); + TDMFREE(pTSBuf); return NULL; } @@ -113,7 +113,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { STSGroupBlockInfoEx* pBlockList = &pTSBuf->pData[i]; memcpy(&pBlockList->info, &buf[i], sizeof(STSGroupBlockInfo)); } - free(buf); + TDMFREE(buf); ret = fseek(pTSBuf->f, 0, SEEK_END); UNUSED(ret); @@ -142,11 +142,11 @@ void* tsBufDestroy(STSBuf* pTSBuf) { return NULL; } - tfree(pTSBuf->assistBuf); - tfree(pTSBuf->tsData.rawBuf); + TDMFREE(pTSBuf->assistBuf); + TDMFREE(pTSBuf->tsData.rawBuf); - tfree(pTSBuf->pData); - tfree(pTSBuf->block.payload); + TDMFREE(pTSBuf->pData); + TDMFREE(pTSBuf->block.payload); fclose(pTSBuf->f); @@ -158,7 +158,7 @@ void* tsBufDestroy(STSBuf* pTSBuf) { } tVariantDestroy(&pTSBuf->block.tag); - free(pTSBuf); + TDMFREE(pTSBuf); return NULL; } diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index dc01de0f92..387fed1b43 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -59,11 +59,11 @@ void cleanupResultRowInfo(SResultRowInfo *pResultRowInfo) { if (pResultRowInfo->type == TSDB_DATA_TYPE_BINARY || pResultRowInfo->type == TSDB_DATA_TYPE_NCHAR) { for(int32_t i = 0; i < pResultRowInfo->size; ++i) { - tfree(pResultRowInfo->pResult[i]->key); + TDMFREE(pResultRowInfo->pResult[i]->key); } } - tfree(pResultRowInfo->pResult); + TDMFREE(pResultRowInfo->pResult); } void resetResultRowInfo(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo) { @@ -143,7 +143,7 @@ void clearResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16 pResultRow->closed = false; if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { - tfree(pResultRow->key); + TDMFREE(pResultRow->key); } else { pResultRow->win = TSWINDOW_INITIALIZER; } @@ -221,11 +221,11 @@ void* destroyResultRowPool(SResultRowPool* p) { size_t size = taosArrayGetSize(p->pData); for(int32_t i = 0; i < size; ++i) { void** ptr = taosArrayGet(p->pData, i); - tfree(*ptr); + TDMFREE(*ptr); } taosArrayDestroy(p->pData); - tfree(p); + TDMFREE(p); return NULL; } \ No newline at end of file diff --git a/src/query/src/sql.c b/src/query/src/sql.c index 7c10a4ce6b..336d263f64 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -1461,7 +1461,7 @@ void ParseFinalize(void *p){ yyParser *pParser = (yyParser*)p; while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); #if YYSTACKDEPTH<=0 - if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); + if( pParser->yystack!=&pParser->yystk0 ) TDMFREE(pParser->yystack); #endif } diff --git a/src/util/src/hash.c b/src/util/src/hash.c index 1a9c6d314b..cfca7edd36 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -172,7 +172,7 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp pHashObj->hashList = (SHashEntry **)calloc(pHashObj->capacity, sizeof(void *)); if (pHashObj->hashList == NULL) { - free(pHashObj); + tdmfree(pHashObj); uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; } else { @@ -526,7 +526,7 @@ void taosHashCleanup(SHashObj *pHashObj) { taosArrayDestroy(pHashObj->pMemBlock); memset(pHashObj, 0, sizeof(SHashObj)); - free(pHashObj); + tdmfree(pHashObj); } // for profile only -- GitLab