From 222db126bcfac5bbce6131f519e9a874b9826e08 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Sat, 26 Mar 2022 00:29:53 +0800 Subject: [PATCH] [TD-13758]: redefine memory api. --- include/common/tcommon.h | 14 +- include/common/tdataformat.h | 8 +- include/common/tmsg.h | 26 +- include/libs/transport/trpc.h | 2 +- include/os/osMemory.h | 25 +- include/util/tcoding.h | 4 +- include/util/tencode.h | 2 +- include/util/tfreelist.h | 4 +- include/util/tlist.h | 2 +- source/client/src/clientEnv.c | 34 +- source/client/src/clientHb.c | 24 +- source/client/src/clientImpl.c | 32 +- source/client/src/clientMsgHandler.c | 30 +- source/client/src/tmq.c | 74 +-- source/common/src/tdatablock.c | 70 +-- source/common/src/tdataformat.c | 54 +- source/common/src/tmsg.c | 58 +- source/common/src/tname.c | 6 +- source/common/src/trow.c | 2 +- source/common/src/ttszip.c | 44 +- source/common/src/tvariant.c | 42 +- source/common/test/commonTests.cpp | 26 +- source/dnode/bnode/src/bnode.c | 4 +- source/dnode/mgmt/bnode/src/bmInt.c | 6 +- source/dnode/mgmt/container/src/dndExec.c | 6 +- source/dnode/mgmt/container/src/dndFile.c | 8 +- source/dnode/mgmt/container/src/dndObj.c | 16 +- source/dnode/mgmt/dnode/src/dmFile.c | 8 +- source/dnode/mgmt/dnode/src/dmInt.c | 4 +- source/dnode/mgmt/mnode/src/mmFile.c | 8 +- source/dnode/mgmt/mnode/src/mmInt.c | 6 +- source/dnode/mgmt/qnode/src/qmInt.c | 6 +- source/dnode/mgmt/snode/src/smInt.c | 6 +- source/dnode/mgmt/snode/src/smWorker.c | 2 +- source/dnode/mgmt/test/sut/inc/sut.h | 2 +- source/dnode/mgmt/test/sut/src/client.cpp | 4 +- source/dnode/mgmt/vnode/src/vmFile.c | 14 +- source/dnode/mgmt/vnode/src/vmInt.c | 24 +- source/dnode/mgmt/vnode/src/vmWorker.c | 2 +- source/dnode/mnode/impl/inc/mndDef.h | 12 +- source/dnode/mnode/impl/src/mndAcct.c | 2 +- source/dnode/mnode/impl/src/mndBnode.c | 14 +- source/dnode/mnode/impl/src/mndCluster.c | 2 +- source/dnode/mnode/impl/src/mndConsumer.c | 12 +- source/dnode/mnode/impl/src/mndDb.c | 16 +- source/dnode/mnode/impl/src/mndDnode.c | 2 +- source/dnode/mnode/impl/src/mndFunc.c | 18 +- source/dnode/mnode/impl/src/mndInfoSchema.c | 6 +- source/dnode/mnode/impl/src/mndMnode.c | 18 +- source/dnode/mnode/impl/src/mndOffset.c | 10 +- source/dnode/mnode/impl/src/mndProfile.c | 14 +- source/dnode/mnode/impl/src/mndQnode.c | 16 +- source/dnode/mnode/impl/src/mndScheduler.c | 4 +- source/dnode/mnode/impl/src/mndShow.c | 2 +- source/dnode/mnode/impl/src/mndSma.c | 34 +- source/dnode/mnode/impl/src/mndSnode.c | 14 +- source/dnode/mnode/impl/src/mndStb.c | 70 +-- source/dnode/mnode/impl/src/mndStream.c | 10 +- source/dnode/mnode/impl/src/mndSubscribe.c | 38 +- source/dnode/mnode/impl/src/mndTelem.c | 2 +- source/dnode/mnode/impl/src/mndTopic.c | 20 +- source/dnode/mnode/impl/src/mndTrans.c | 26 +- source/dnode/mnode/impl/src/mndUser.c | 2 +- source/dnode/mnode/impl/src/mndVgroup.c | 10 +- source/dnode/mnode/impl/src/mnode.c | 8 +- source/dnode/mnode/impl/test/trans/trans.cpp | 4 +- source/dnode/mnode/sdb/src/sdb.c | 10 +- source/dnode/mnode/sdb/src/sdbFile.c | 6 +- source/dnode/mnode/sdb/src/sdbRaw.c | 4 +- source/dnode/mnode/sdb/src/sdbRow.c | 4 +- source/dnode/qnode/src/qnode.c | 6 +- source/dnode/snode/src/snode.c | 18 +- source/dnode/vnode/src/inc/tsdbMemory.h | 6 +- source/dnode/vnode/src/meta/metaBDBImpl.c | 56 +- source/dnode/vnode/src/meta/metaMain.c | 6 +- source/dnode/vnode/src/meta/metaTDBImpl.c | 2 +- source/dnode/vnode/src/tq/tq.c | 32 +- source/dnode/vnode/src/tq/tqMetaStore.c | 46 +- source/dnode/vnode/src/tq/tqOffset.c | 2 +- source/dnode/vnode/src/tq/tqPush.c | 12 +- source/dnode/vnode/src/tq/tqRead.c | 6 +- source/dnode/vnode/src/tsdb/tsdbBDBImpl.c | 4 +- source/dnode/vnode/src/tsdb/tsdbCommit.c | 14 +- source/dnode/vnode/src/tsdb/tsdbFS.c | 24 +- source/dnode/vnode/src/tsdb/tsdbFile.c | 14 +- source/dnode/vnode/src/tsdb/tsdbMain.c | 30 +- source/dnode/vnode/src/tsdb/tsdbMemTable.c | 26 +- source/dnode/vnode/src/tsdb/tsdbRead.c | 66 +- source/dnode/vnode/src/tsdb/tsdbSma.c | 30 +- source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c | 10 +- source/dnode/vnode/src/vnd/vnodeBufferPool.c | 12 +- source/dnode/vnode/src/vnd/vnodeCommit.c | 2 +- source/dnode/vnode/src/vnd/vnodeMain.c | 6 +- source/dnode/vnode/src/vnd/vnodeMgr.c | 6 +- source/dnode/vnode/src/vnd/vnodeQuery.c | 18 +- source/dnode/vnode/src/vnd/vnodeWrite.c | 24 +- source/dnode/vnode/test/tqMetaTest.cpp | 18 +- source/dnode/vnode/test/tsdbSmaTest.cpp | 30 +- source/libs/catalog/src/catalog.c | 110 ++-- source/libs/catalog/test/catalogTests.cpp | 66 +- source/libs/executor/src/dataDispatcher.c | 10 +- source/libs/executor/src/executil.c | 30 +- source/libs/executor/src/executorimpl.c | 356 +++++------ source/libs/executor/src/tlinearhash.c | 16 +- source/libs/executor/src/tsimplehash.c | 14 +- source/libs/executor/src/tsort.c | 14 +- source/libs/executor/test/executorTests.cpp | 62 +- source/libs/executor/test/sortTests.cpp | 14 +- source/libs/function/CMakeLists.txt | 2 + source/libs/function/src/taggfunction.c | 12 +- source/libs/function/src/texpr.c | 30 +- source/libs/function/src/tfill.c | 28 +- source/libs/function/src/thistogram.c | 16 +- source/libs/function/src/tpercentile.c | 18 +- source/libs/function/src/tscript.c | 12 +- source/libs/function/src/tudf.c | 78 +-- source/libs/function/src/udfd.c | 82 +-- source/libs/function/test/runUdf.c | 9 +- source/libs/function/test/udf1.c | 5 +- source/libs/index/src/index.c | 46 +- source/libs/index/src/index_cache.c | 28 +- source/libs/index/src/index_comm.c | 2 +- source/libs/index/src/index_fst.c | 78 +-- source/libs/index/src/index_fst_automation.c | 20 +- .../index/src/index_fst_counting_writer.c | 20 +- source/libs/index/src/index_fst_node.c | 6 +- source/libs/index/src/index_fst_registry.c | 10 +- source/libs/index/src/index_fst_util.c | 14 +- source/libs/index/src/index_tfile.c | 52 +- source/libs/index/src/index_util.c | 10 +- source/libs/index/test/fstTest.cc | 8 +- source/libs/index/test/fstUT.cc | 4 +- source/libs/index/test/indexTests.cc | 14 +- source/libs/monitor/src/monitor.c | 6 +- source/libs/nodes/src/nodesCloneFuncs.c | 6 +- source/libs/nodes/src/nodesCodeFuncs.c | 2 +- source/libs/nodes/src/nodesUtilFuncs.c | 30 +- source/libs/parser/src/parAstCreater.c | 2 +- source/libs/parser/src/parAstParser.c | 6 +- source/libs/parser/src/parInsert.c | 16 +- source/libs/parser/src/parInsertData.c | 40 +- source/libs/parser/src/parTokenizer.c | 4 +- source/libs/parser/src/parTranslater.c | 124 ++-- source/libs/parser/src/parUtil.c | 2 +- source/libs/parser/src/parser.c | 8 +- source/libs/parser/src/sql.c | 8 +- .../libs/parser/test/mockCatalogService.cpp | 4 +- source/libs/parser/test/mockCatalogService.h | 2 +- source/libs/parser/test/parserAstTest.cpp | 2 +- source/libs/planner/src/planScaleOut.c | 2 +- source/libs/planner/src/planSpliter.c | 2 +- source/libs/planner/test/plannerTest.cpp | 2 +- source/libs/qcom/src/querymsg.c | 6 +- source/libs/qcom/test/queryTest.cpp | 10 +- source/libs/qworker/src/qworker.c | 14 +- source/libs/qworker/src/qworkerMsg.c | 4 +- source/libs/qworker/test/qworkerTests.cpp | 12 +- source/libs/scalar/inc/filterInt.h | 2 +- source/libs/scalar/src/filter.c | 154 ++--- source/libs/scalar/src/scalar.c | 34 +- source/libs/scalar/src/sclfunc.c | 26 +- source/libs/scalar/src/sclvector.c | 52 +- .../libs/scalar/test/filter/filterTests.cpp | 48 +- .../libs/scalar/test/scalar/scalarTests.cpp | 12 +- source/libs/scheduler/src/scheduler.c | 46 +- source/libs/scheduler/test/schedulerTests.cpp | 48 +- source/libs/stream/src/tstream.c | 8 +- source/libs/sync/src/syncEnv.c | 2 +- source/libs/sync/src/syncIO.c | 2 +- source/libs/sync/src/syncIndexMgr.c | 16 +- source/libs/sync/src/syncMain.c | 16 +- source/libs/sync/src/syncMessage.c | 160 ++--- source/libs/sync/src/syncRaftEntry.c | 20 +- source/libs/sync/src/syncRaftLog.c | 28 +- source/libs/sync/src/syncRaftStore.c | 14 +- source/libs/sync/src/syncReplication.c | 2 +- source/libs/sync/src/syncUtil.c | 10 +- source/libs/sync/src/syncVoteMgr.c | 32 +- .../sync/test/syncAppendEntriesReplyTest.cpp | 6 +- .../libs/sync/test/syncAppendEntriesTest.cpp | 8 +- .../libs/sync/test/syncClientRequestTest.cpp | 8 +- source/libs/sync/test/syncElectTest.cpp | 2 +- source/libs/sync/test/syncElectTest2.cpp | 2 +- source/libs/sync/test/syncElectTest3.cpp | 2 +- source/libs/sync/test/syncEncodeTest.cpp | 12 +- source/libs/sync/test/syncEnqTest.cpp | 2 +- source/libs/sync/test/syncEntryTest.cpp | 2 +- source/libs/sync/test/syncIOSendMsgTest.cpp | 2 +- source/libs/sync/test/syncIndexMgrTest.cpp | 10 +- source/libs/sync/test/syncInitTest.cpp | 2 +- source/libs/sync/test/syncLogStoreTest.cpp | 2 +- source/libs/sync/test/syncPingReplyTest.cpp | 8 +- source/libs/sync/test/syncPingSelfTest.cpp | 2 +- source/libs/sync/test/syncPingTest.cpp | 8 +- source/libs/sync/test/syncPingTimerTest.cpp | 2 +- source/libs/sync/test/syncPingTimerTest2.cpp | 2 +- source/libs/sync/test/syncRaftStoreTest.cpp | 2 +- source/libs/sync/test/syncRefTest.cpp | 4 +- .../libs/sync/test/syncReplicateLoadTest.cpp | 8 +- source/libs/sync/test/syncReplicateTest.cpp | 8 +- source/libs/sync/test/syncReplicateTest2.cpp | 10 +- source/libs/sync/test/syncReplicateTest3.cpp | 10 +- .../sync/test/syncRequestVoteReplyTest.cpp | 6 +- source/libs/sync/test/syncRequestVoteTest.cpp | 6 +- source/libs/sync/test/syncTimeoutTest.cpp | 8 +- .../libs/sync/test/syncVotesGrantedTest.cpp | 14 +- .../libs/sync/test/syncVotesRespondTest.cpp | 14 +- source/libs/sync/test/syncWriteTest.cpp | 8 +- source/libs/tdb/src/db/tdbBtree.c | 6 +- source/libs/tdb/src/db/tdbDb.c | 2 +- source/libs/tdb/src/db/tdbEnv.c | 2 +- source/libs/tdb/src/db/tdbPCache.c | 10 +- source/libs/tdb/src/db/tdbPager.c | 2 +- source/libs/tfs/src/tfs.c | 20 +- source/libs/tfs/src/tfsDisk.c | 8 +- source/libs/tfs/test/tfsTest.cpp | 2 +- source/libs/transport/inc/transComm.h | 4 +- source/libs/transport/src/rpcCache.c | 18 +- source/libs/transport/src/rpcMain.c | 32 +- source/libs/transport/src/rpcTcp.c | 50 +- source/libs/transport/src/rpcUdp.c | 10 +- source/libs/transport/src/thttp.c | 8 +- source/libs/transport/src/trans.c | 10 +- source/libs/transport/src/transCli.c | 50 +- source/libs/transport/src/transComm.c | 42 +- source/libs/transport/src/transSrv.c | 74 +-- source/libs/transport/test/rclient.c | 2 +- source/libs/transport/test/rsclient.c | 2 +- source/libs/transport/test/syncClient.c | 2 +- source/libs/transport/test/transportTests.cpp | 50 +- source/libs/transport/test/uv.c | 42 +- source/libs/wal/src/walMeta.c | 18 +- source/libs/wal/src/walMgmt.c | 12 +- source/libs/wal/src/walRead.c | 18 +- source/libs/wal/test/walMetaTest.cpp | 18 +- source/os/src/osFile.c | 4 +- source/os/src/osLocale.c | 4 +- source/os/src/osMemory.c | 136 +++++ source/os/src/osSemaphore.c | 4 +- source/os/src/osSocket.c | 16 +- source/os/src/osString.c | 11 +- source/os/src/osSysinfo.c | 18 +- source/util/src/talgo.c | 12 +- source/util/src/tarray.c | 14 +- source/util/src/tbase64.c | 6 +- source/util/src/tbuffer.c | 2 +- source/util/src/tcache.c | 38 +- source/util/src/tcompare.c | 24 +- source/util/src/tconfig.c | 20 +- source/util/src/tcrc32c.c | 6 +- source/util/src/tdes.c | 6 +- source/util/src/tencode.c | 10 +- source/util/src/tfunctional.c | 6 +- source/util/src/thash.c | 36 +- source/util/src/theap.c | 4 +- source/util/src/tidpool.c | 14 +- source/util/src/tjson.c | 2 +- source/util/src/tlist.c | 10 +- source/util/src/tlog.c | 12 +- source/util/src/tlosertree.c | 4 +- source/util/src/tmallocator.c | 6 +- source/util/src/tmempool.c | 18 +- source/util/src/tpagedbuf.c | 30 +- source/util/src/tprocess.c | 14 +- source/util/src/tqueue.c | 18 +- source/util/src/tref.c | 18 +- source/util/src/tsched.c | 12 +- source/util/src/tskiplist.c | 18 +- source/util/src/tstrbuild.c | 4 +- source/util/src/tthread.c | 6 +- source/util/src/ttimer.c | 18 +- source/util/src/tutil.c | 6 +- source/util/src/tworker.c | 8 +- source/util/test/hashTest.cpp | 8 +- source/util/test/skiplistTest.cpp | 30 +- source/util/test/stringTest.cpp | 16 +- source/util/test/trefTest.c | 18 +- tests/script/api/batchprepare.c | 470 +++++++-------- tests/script/api/stmtBatchTest.c | 568 +++++++++--------- tests/script/api/stmtTest.c | 2 +- tests/script/api/stmt_function.c | 66 +- tests/script/http/httpTest.c | 12 +- tests/script/http/httpTestSqlUtc.c | 12 +- tests/script/http/httpTestSqlt.c | 12 +- tests/script/sh/sum_double.c | 4 +- tests/test/c/create_table.c | 8 +- tests/test/c/tmqDemo.c | 16 +- tests/tsim/src/simParse.c | 8 +- tests/tsim/src/simSystem.c | 12 +- tools/shell/src/backup/shellCheck.c | 12 +- tools/shell/src/backup/shellDarwin.c | 16 +- tools/shell/src/backup/shellImport.c | 24 +- tools/shell/src/backup/shellWindows.c | 16 +- tools/shell/src/shellCommand.c | 10 +- tools/shell/src/shellEngine.c | 18 +- tools/shell/src/shellMain.c | 16 +- tools/shell/src/tnettest.c | 18 +- 297 files changed, 3410 insertions(+), 3258 deletions(-) create mode 100644 source/os/src/osMemory.c diff --git a/include/common/tcommon.h b/include/common/tcommon.h index b52397bb86..eb9f450872 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -104,16 +104,16 @@ static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) { for (int32_t i = 0; i < numOfOutput; ++i) { SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i); if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - tfree(pColInfoData->varmeta.offset); + taosMemoryFreeClear(pColInfoData->varmeta.offset); } else { - tfree(pColInfoData->nullbitmap); + taosMemoryFreeClear(pColInfoData->nullbitmap); } - tfree(pColInfoData->pData); + taosMemoryFreeClear(pColInfoData->pData); } taosArrayDestroy(pBlock->pDataBlock); - tfree(pBlock->pBlockAgg); + taosMemoryFreeClear(pBlock->pBlockAgg); } static FORCE_INLINE void tDeleteSSDataBlock(SSDataBlock* pBlock) { blockDestroyInner(pBlock); } @@ -147,7 +147,7 @@ static FORCE_INLINE void* tDecodeSMqPollRsp(void* buf, SMqPollRsp* pRsp) { buf = taosDecodeFixedI32(buf, &pRsp->skipLogNum); buf = taosDecodeFixedI32(buf, &pRsp->numOfTopics); if (pRsp->numOfTopics == 0) return buf; - pRsp->schema = (SSchemaWrapper*)calloc(1, sizeof(SSchemaWrapper)); + pRsp->schema = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper)); if (pRsp->schema == NULL) return NULL; buf = tDecodeSSchemaWrapper(buf, pRsp->schema); buf = taosDecodeFixedI32(buf, &sz); @@ -163,9 +163,9 @@ static FORCE_INLINE void* tDecodeSMqPollRsp(void* buf, SMqPollRsp* pRsp) { static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqPollRsp* pRsp) { if (pRsp->schema) { if (pRsp->schema->nCols) { - tfree(pRsp->schema->pSchema); + taosMemoryFreeClear(pRsp->schema->pSchema); } - free(pRsp->schema); + taosMemoryFree(pRsp->schema); } taosArrayDestroyEx(pRsp->pBlockData, (void (*)(void*))blockDestroyInner); pRsp->pBlockData = NULL; diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 89a0e6b4dc..698352f636 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -93,7 +93,7 @@ typedef struct { #define schemaFLen(s) ((s)->flen) #define schemaVLen(s) ((s)->vlen) #define schemaColAt(s, i) ((s)->columns + i) -#define tdFreeSchema(s) tfree((s)) +#define tdFreeSchema(s) taosMemoryFreeClear((s)) STSchema *tdDupSchema(const STSchema *pSchema); int32_t tdEncodeSchema(void **buf, STSchema *pSchema); @@ -493,7 +493,7 @@ typedef struct { #define kvRowCpy(dst, r) memcpy((dst), (r), kvRowLen(r)) #define kvRowColVal(r, colIdx) POINTER_SHIFT(kvRowValues(r), (colIdx)->offset) #define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i)) -#define kvRowFree(r) tfree(r) +#define kvRowFree(r) taosMemoryFreeClear(r) #define kvRowEnd(r) POINTER_SHIFT(r, kvRowLen(r)) #define kvRowValLen(r) (kvRowLen(r) - TD_KV_ROW_HEAD_SIZE - sizeof(SColIdx) * kvRowNCols(r)) #define kvRowTKey(r) (*(TKEY *)(kvRowValues(r))) @@ -593,7 +593,7 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder); static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, const void *value) { if (pBuilder->nCols >= pBuilder->tCols) { pBuilder->tCols *= 2; - SColIdx *pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols); + SColIdx *pColIdx = (SColIdx *)taosMemoryRealloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols); if (pColIdx == NULL) return -1; pBuilder->pColIdx = pColIdx; } @@ -608,7 +608,7 @@ static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t col while (tlen > pBuilder->alloc - pBuilder->size) { pBuilder->alloc *= 2; } - void *buf = realloc(pBuilder->buf, pBuilder->alloc); + void *buf = taosMemoryRealloc(pBuilder->buf, pBuilder->alloc); if (buf == NULL) return -1; pBuilder->buf = buf; } diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 0ed2a6a006..136a576c7c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1309,7 +1309,7 @@ typedef struct { } SMqRebSubscribe; static FORCE_INLINE SMqRebSubscribe* tNewSMqRebSubscribe(const char* key) { - SMqRebSubscribe* pRebSub = (SMqRebSubscribe*)calloc(1, sizeof(SMqRebSubscribe)); + SMqRebSubscribe* pRebSub = (SMqRebSubscribe*)taosMemoryCalloc(1, sizeof(SMqRebSubscribe)); if (pRebSub == NULL) { goto _err; } @@ -1331,7 +1331,7 @@ _err: taosArrayDestroy(pRebSub->lostConsumers); taosArrayDestroy(pRebSub->removedConsumers); taosArrayDestroy(pRebSub->newConsumers); - tfree(pRebSub); + taosMemoryFreeClear(pRebSub); return NULL; } @@ -1632,7 +1632,7 @@ static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) { void* pIter = taosHashIterate(info, NULL); while (pIter != NULL) { SKv* kv = (SKv*)pIter; - tfree(kv->value); + taosMemoryFreeClear(kv->value); pIter = taosHashIterate(info, pIter); } } @@ -1655,13 +1655,13 @@ static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq, bool deep) { } else { taosArrayDestroy(req->reqs); } - free(pReq); + taosMemoryFree(pReq); } static FORCE_INLINE void tFreeClientKv(void* pKv) { SKv* kv = (SKv*)pKv; if (kv) { - tfree(kv->value); + taosMemoryFreeClear(kv->value); } } @@ -1688,7 +1688,7 @@ static FORCE_INLINE int32_t tEncodeSKv(SCoder* pEncoder, const SKv* pKv) { static FORCE_INLINE int32_t tDecodeSKv(SCoder* pDecoder, SKv* pKv) { if (tDecodeI32(pDecoder, &pKv->key) < 0) return -1; if (tDecodeI32(pDecoder, &pKv->valueLen) < 0) return -1; - pKv->value = malloc(pKv->valueLen + 1); + pKv->value = taosMemoryMalloc(pKv->valueLen + 1); if (pKv->value == NULL) return -1; if (tDecodeCStrTo(pDecoder, (char*)pKv->value) < 0) return -1; return 0; @@ -1942,7 +1942,7 @@ static FORCE_INLINE int32_t tEncodeSSchemaWrapper(void** buf, const SSchemaWrapp static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) { buf = taosDecodeFixedU32(buf, &pSW->nCols); - pSW->pSchema = (SSchema*)calloc(pSW->nCols, sizeof(SSchema)); + pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema)); if (pSW->pSchema == NULL) { return NULL; } @@ -2077,8 +2077,8 @@ typedef struct { static FORCE_INLINE void tdDestroyTSma(STSma* pSma) { if (pSma) { - tfree(pSma->expr); - tfree(pSma->tagsFilter); + taosMemoryFreeClear(pSma->expr); + taosMemoryFreeClear(pSma->tagsFilter); } } @@ -2088,14 +2088,14 @@ static FORCE_INLINE void tdDestroyTSmaWrapper(STSmaWrapper* pSW) { for (uint32_t i = 0; i < pSW->number; ++i) { tdDestroyTSma(pSW->tSma + i); } - tfree(pSW->tSma); + taosMemoryFreeClear(pSW->tSma); } } } static FORCE_INLINE void tdFreeTSmaWrapper(STSmaWrapper* pSW) { tdDestroyTSmaWrapper(pSW); - tfree(pSW); + taosMemoryFreeClear(pSW); } static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) { @@ -2173,7 +2173,7 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) { static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) { buf = taosDecodeFixedU32(buf, &pSW->number); - pSW->tSma = (STSma*)calloc(pSW->number, sizeof(STSma)); + pSW->tSma = (STSma*)taosMemoryCalloc(pSW->number, sizeof(STSma)); if (pSW->tSma == NULL) { return NULL; } @@ -2183,7 +2183,7 @@ static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) { for (uint32_t j = i; j >= 0; --i) { tdDestroyTSma(pSW->tSma + j); } - free(pSW->tSma); + taosMemoryFree(pSW->tSma); return NULL; } } diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 02029a996c..6112a77a12 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -83,7 +83,7 @@ typedef struct SRpcInit { typedef struct { void * val; int32_t len; - void (*free)(void *arg); + void (*freeFunc)(const void *arg); } SRpcCtxVal; typedef struct { diff --git a/include/os/osMemory.h b/include/os/osMemory.h index 6100419035..62ac82782c 100644 --- a/include/os/osMemory.h +++ b/include/os/osMemory.h @@ -20,12 +20,25 @@ extern "C" { #endif -#define tfree(x) \ - do { \ - if (x) { \ - free((void *)(x)); \ - (x) = 0; \ - } \ +// If the error is in a third-party library, place this header file under the third-party library header file. +// When you want to use this feature, you should find or add the same function in the following sectio +#ifndef ALLOW_FORBID_FUNC + #define malloc MALLOC_FUNC_TAOS_FORBID + #define calloc CALLOC_FUNC_TAOS_FORBID + #define realloc REALLOC_FUNC_TAOS_FORBID + #define free FREE_FUNC_TAOS_FORBID +#endif + +void *taosMemoryMalloc(int32_t size); +void *taosMemoryCalloc(int32_t num, int32_t size); +void *taosMemoryRealloc(void *ptr, int32_t size); +void taosMemoryFree(const void *ptr); +int32_t taosMemorySize(void *ptr); + +#define taosMemoryFreeClear(ptr) \ + do { \ + taosMemoryFree(ptr); \ + (ptr)=NULL; \ } while (0) #ifdef __cplusplus diff --git a/include/util/tcoding.h b/include/util/tcoding.h index 943a1f9eca..838b175a28 100644 --- a/include/util/tcoding.h +++ b/include/util/tcoding.h @@ -351,7 +351,7 @@ static FORCE_INLINE void *taosDecodeString(const void *buf, char **value) { uint64_t size = 0; buf = taosDecodeVariantU64(buf, &size); - *value = (char *)malloc((size_t)size + 1); + *value = (char *)taosMemoryMalloc((size_t)size + 1); if (*value == NULL) return NULL; memcpy(*value, buf, (size_t)size); @@ -386,7 +386,7 @@ static FORCE_INLINE int32_t taosEncodeBinary(void **buf, const void *value, int3 } static FORCE_INLINE void *taosDecodeBinary(const void *buf, void **value, int32_t valueLen) { - *value = malloc((size_t)valueLen); + *value = taosMemoryMalloc((size_t)valueLen); if (*value == NULL) return NULL; memcpy(*value, buf, (size_t)valueLen); diff --git a/include/util/tencode.h b/include/util/tencode.h index 7e1b624dfb..cdde378b69 100644 --- a/include/util/tencode.h +++ b/include/util/tencode.h @@ -406,7 +406,7 @@ static FORCE_INLINE int32_t tDecodeBinaryAlloc(SCoder* pDecoder, void** val, uin if (tDecodeU64v(pDecoder, len) < 0) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1; - *val = malloc(*len); + *val = taosMemoryMalloc(*len); if (*val == NULL) return -1; memcpy(*val, TD_CODER_CURRENT(pDecoder), *len); diff --git a/include/util/tfreelist.h b/include/util/tfreelist.h index 0a507aeec9..e9b5ca5fca 100644 --- a/include/util/tfreelist.h +++ b/include/util/tfreelist.h @@ -31,7 +31,7 @@ typedef TD_SLIST(SFreeListNode) SFreeList; #define TFL_MALLOC(PTR, TYPE, SIZE, LIST) \ do { \ - void *ptr = malloc((SIZE) + sizeof(struct SFreeListNode)); \ + void *ptr = taosMemoryMalloc((SIZE) + sizeof(struct SFreeListNode)); \ if (ptr) { \ TD_SLIST_PUSH((LIST), (struct SFreeListNode *)ptr); \ ptr = ((struct SFreeListNode *)ptr)->payload; \ @@ -49,7 +49,7 @@ static FORCE_INLINE void tFreeListClear(SFreeList *pFL) { pNode = TD_SLIST_HEAD(pFL); if (pNode == NULL) break; TD_SLIST_POP(pFL); - free(pNode); + taosMemoryFree(pNode); } } diff --git a/include/util/tlist.h b/include/util/tlist.h index caa6424918..43833d7ecd 100644 --- a/include/util/tlist.h +++ b/include/util/tlist.h @@ -216,7 +216,7 @@ typedef struct { #define listNEles(l) TD_DLIST_NELES(l) #define listEleSize(l) ((l)->eleSize) #define isListEmpty(l) (TD_DLIST_NELES(l) == 0) -#define listNodeFree(n) free(n) +#define listNodeFree(n) taosMemoryFree(n) void tdListInit(SList *list, int32_t eleSize); void tdListEmpty(SList *list); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 505c0eeb67..f328f518ac 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -115,11 +115,11 @@ void destroyTscObj(void *pObj) { atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1); tscDebug("connObj 0x%" PRIx64 " destroyed, totalConn:%" PRId64, pTscObj->id, pTscObj->pAppInfo->numOfConns); taosThreadMutexDestroy(&pTscObj->mutex); - tfree(pTscObj); + taosMemoryFreeClear(pTscObj); } void *createTscObj(const char *user, const char *auth, const char *db, SAppInstInfo *pAppInfo) { - STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); + STscObj *pObj = (STscObj *)taosMemoryCalloc(1, sizeof(STscObj)); if (NULL == pObj) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; @@ -143,7 +143,7 @@ void *createTscObj(const char *user, const char *auth, const char *db, SAppInstI void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t type) { assert(pObj != NULL); - SRequestObj *pRequest = (SRequestObj *)calloc(1, sizeof(SRequestObj)); + SRequestObj *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj)); if (NULL == pRequest) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; @@ -156,7 +156,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty pRequest->type = type; pRequest->pTscObj = pObj; pRequest->body.fp = fp; // not used it yet - pRequest->msgBuf = calloc(1, ERROR_MSG_BUF_DEFAULT_SIZE); + pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE); tsem_init(&pRequest->body.rspSem, 0, 0); registerRequest(pRequest); @@ -164,17 +164,17 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty } static void doFreeReqResultInfo(SReqResultInfo *pResInfo) { - tfree(pResInfo->pRspMsg); - tfree(pResInfo->length); - tfree(pResInfo->row); - tfree(pResInfo->pCol); - tfree(pResInfo->fields); + taosMemoryFreeClear(pResInfo->pRspMsg); + taosMemoryFreeClear(pResInfo->length); + taosMemoryFreeClear(pResInfo->row); + taosMemoryFreeClear(pResInfo->pCol); + taosMemoryFreeClear(pResInfo->fields); if (pResInfo->convertBuf != NULL) { for (int32_t i = 0; i < pResInfo->numOfCols; ++i) { - tfree(pResInfo->convertBuf[i]); + taosMemoryFreeClear(pResInfo->convertBuf[i]); } - tfree(pResInfo->convertBuf); + taosMemoryFreeClear(pResInfo->convertBuf); } } @@ -184,10 +184,10 @@ static void doDestroyRequest(void *p) { assert(RID_VALID(pRequest->self)); - tfree(pRequest->msgBuf); - tfree(pRequest->sqlstr); - tfree(pRequest->pInfo); - tfree(pRequest->pDb); + taosMemoryFreeClear(pRequest->msgBuf); + taosMemoryFreeClear(pRequest->sqlstr); + taosMemoryFreeClear(pRequest->pInfo); + taosMemoryFreeClear(pRequest->pDb); doFreeReqResultInfo(&pRequest->body.resInfo); qDestroyQueryPlan(pRequest->body.pDag); @@ -197,7 +197,7 @@ static void doDestroyRequest(void *p) { } deregisterRequest(pRequest); - tfree(pRequest); + taosMemoryFreeClear(pRequest); } void destroyRequest(SRequestObj *pRequest) { @@ -356,7 +356,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { tscInfo("charset:%s is not valid in locale, charset remains:%s", charset, tsCharset); } - free(charset); + taosMemoryFree(charset); } else { // it may be windows system tscInfo("charset remains:%s", tsCharset); } diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 479281eec6..832a415efa 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -166,7 +166,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { static int32_t hbAsyncCallBack(void *param, const SDataBuf *pMsg, int32_t code) { static int32_t emptyRspNum = 0; if (code != 0) { - tfree(param); + taosMemoryFreeClear(param); return -1; } @@ -179,12 +179,12 @@ static int32_t hbAsyncCallBack(void *param, const SDataBuf *pMsg, int32_t code) SAppInstInfo **pInst = taosHashGet(appInfo.pInstMap, key, strlen(key)); if (pInst == NULL || NULL == *pInst) { tscError("cluster not exist, key:%s", key); - tfree(param); + taosMemoryFreeClear(param); tFreeClientHbBatchRsp(&pRsp); return -1; } - tfree(param); + taosMemoryFreeClear(param); if (rspNum) { tscDebug("hb got %d rsp, %d empty rsp received before", rspNum, @@ -317,7 +317,7 @@ void hbFreeReq(void *req) { } SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) { - SClientHbBatchReq *pBatchReq = calloc(1, sizeof(SClientHbBatchReq)); + SClientHbBatchReq *pBatchReq = taosMemoryCalloc(1, sizeof(SClientHbBatchReq)); if (pBatchReq == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; @@ -346,7 +346,7 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) { if (code) { taosArrayDestroyEx(pBatchReq->reqs, hbFreeReq); - tfree(pBatchReq); + taosMemoryFreeClear(pBatchReq); } return pBatchReq; @@ -387,7 +387,7 @@ static void *hbThreadFunc(void *param) { continue; } int tlen = tSerializeSClientHbBatchReq(NULL, 0, pReq); - void *buf = malloc(tlen); + void *buf = taosMemoryMalloc(tlen); if (buf == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tFreeClientHbBatchReq(pReq, false); @@ -396,13 +396,13 @@ static void *hbThreadFunc(void *param) { } tSerializeSClientHbBatchReq(buf, tlen, pReq); - SMsgSendInfo *pInfo = calloc(1, sizeof(SMsgSendInfo)); + SMsgSendInfo *pInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (pInfo == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tFreeClientHbBatchReq(pReq, false); hbClearReqInfo(pAppHbMgr); - free(buf); + taosMemoryFree(buf); break; } pInfo->fp = hbAsyncCallBack; @@ -458,7 +458,7 @@ static void hbStopThread() { SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) { hbMgrInit(); - SAppHbMgr *pAppHbMgr = malloc(sizeof(SAppHbMgr)); + SAppHbMgr *pAppHbMgr = taosMemoryMalloc(sizeof(SAppHbMgr)); if (pAppHbMgr == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -478,7 +478,7 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) { if (pAppHbMgr->activeInfo == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - free(pAppHbMgr); + taosMemoryFree(pAppHbMgr); return NULL; } @@ -488,7 +488,7 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) { if (pAppHbMgr->connInfo == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - free(pAppHbMgr); + taosMemoryFree(pAppHbMgr); return NULL; } @@ -580,7 +580,7 @@ int hbRegisterConn(SAppHbMgr *pAppHbMgr, int32_t connId, int64_t clusterId, int3 switch (hbType) { case HEARTBEAT_TYPE_QUERY: { - int64_t *pClusterId = malloc(sizeof(int64_t)); + int64_t *pClusterId = taosMemoryMalloc(sizeof(int64_t)); *pClusterId = clusterId; info.param = pClusterId; diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 47e92ed0ca..0fa1391b6e 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -100,7 +100,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, pInst = taosHashGet(appInfo.pInstMap, key, strlen(key)); SAppInstInfo* p = NULL; if (pInst == NULL) { - p = calloc(1, sizeof(struct SAppInstInfo)); + p = taosMemoryCalloc(1, sizeof(struct SAppInstInfo)); p->mgmtEp = epSet; p->pTransporter = openTransporter(user, secretEncrypt, tsNumOfCores); p->pAppHbMgr = appHbMgrInit(p, key); @@ -111,7 +111,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, taosThreadMutexUnlock(&appInfo.mutex); - tfree(key); + taosMemoryFreeClear(key); return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst); } @@ -122,7 +122,7 @@ int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj* return TSDB_CODE_TSC_OUT_OF_MEMORY; } - (*pRequest)->sqlstr = malloc(sqlLen + 1); + (*pRequest)->sqlstr = taosMemoryMalloc(sqlLen + 1); if ((*pRequest)->sqlstr == NULL) { tscError("0x%" PRIx64 " failed to prepare sql string buffer", (*pRequest)->self); (*pRequest)->msgBuf = strdup("failed to prepare sql string buffer"); @@ -212,7 +212,7 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t assert(pSchema != NULL && numOfCols > 0); pResInfo->numOfCols = numOfCols; - pResInfo->fields = calloc(numOfCols, sizeof(pSchema[0])); + pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(pSchema[0])); for (int32_t i = 0; i < pResInfo->numOfCols; ++i) { pResInfo->fields[i].bytes = pSchema[i].bytes; @@ -421,7 +421,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t } static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) { - SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); + SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (pMsgSendInfo == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; @@ -441,14 +441,14 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) { if (db != NULL) { tstrncpy(connectReq.db, db, sizeof(connectReq.db)); } - tfree(db); + taosMemoryFreeClear(db); connectReq.pid = htonl(appInfo.pid); connectReq.startTime = htobe64(appInfo.startTime); tstrncpy(connectReq.app, appInfo.appName, sizeof(connectReq.app)); int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq); - void* pReq = malloc(contLen); + void* pReq = taosMemoryMalloc(contLen); tSerializeSConnectReq(pReq, contLen, &connectReq); pMsgSendInfo->msgInfo.len = contLen; @@ -458,8 +458,8 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) { static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { assert(pMsgBody != NULL); - tfree(pMsgBody->msgInfo.pData); - tfree(pMsgBody); + taosMemoryFreeClear(pMsgBody->msgInfo.pData); + taosMemoryFreeClear(pMsgBody); } bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType) { return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP || msgType == TDMT_VND_QUERY_HEARTBEAT_RSP; @@ -500,7 +500,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { SDataBuf buf = {.len = pMsg->contLen, .pData = NULL, .handle = pMsg->handle}; if (pMsg->contLen > 0) { - buf.pData = calloc(1, pMsg->contLen); + buf.pData = taosMemoryCalloc(1, pMsg->contLen); if (buf.pData == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; pMsg->code = TSDB_CODE_OUT_OF_MEMORY; @@ -592,7 +592,7 @@ void* doFetchRow(SRequestObj* pRequest) { } SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex); - SVShowTablesReq* pShowReq = calloc(1, sizeof(SVShowTablesReq)); + SVShowTablesReq* pShowReq = taosMemoryCalloc(1, sizeof(SVShowTablesReq)); pShowReq->head.vgId = htonl(pVgroupInfo->vgId); pRequest->body.requestMsg.len = sizeof(SVShowTablesReq); @@ -670,10 +670,10 @@ _return: static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { if (pResInfo->row == NULL) { - pResInfo->row = calloc(pResInfo->numOfCols, POINTER_BYTES); - pResInfo->pCol = calloc(pResInfo->numOfCols, sizeof(SResultColumn)); - pResInfo->length = calloc(pResInfo->numOfCols, sizeof(int32_t)); - pResInfo->convertBuf = calloc(pResInfo->numOfCols, POINTER_BYTES); + pResInfo->row = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); + pResInfo->pCol = taosMemoryCalloc(pResInfo->numOfCols, sizeof(SResultColumn)); + pResInfo->length = taosMemoryCalloc(pResInfo->numOfCols, sizeof(int32_t)); + pResInfo->convertBuf = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); if (pResInfo->row == NULL || pResInfo->pCol == NULL || pResInfo->length == NULL || pResInfo->convertBuf == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -681,7 +681,7 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { for(int32_t i = 0; i < pResInfo->numOfCols; ++i) { if(pResInfo->fields[i].type == TSDB_DATA_TYPE_NCHAR) { - pResInfo->convertBuf[i] = calloc(1, NCHAR_WIDTH_TO_BYTES(pResInfo->fields[i].bytes)); + pResInfo->convertBuf[i] = taosMemoryCalloc(1, NCHAR_WIDTH_TO_BYTES(pResInfo->fields[i].bytes)); } } } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 9c2b23d740..4314391743 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -32,7 +32,7 @@ int32_t genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; setErrno(pRequest, code); - free(pMsg->pData); + taosMemoryFree(pMsg->pData); tsem_post(&pRequest->body.rspSem); return code; } @@ -40,7 +40,7 @@ int32_t genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { - free(pMsg->pData); + taosMemoryFree(pMsg->pData); setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; @@ -77,13 +77,13 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId, pTscObj->pAppInfo->numOfConns); - free(pMsg->pData); + taosMemoryFree(pMsg->pData); tsem_post(&pRequest->body.rspSem); return 0; } SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) { - SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); + SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); pMsgSendInfo->requestObjRefId = pRequest->self; pMsgSendInfo->requestId = pRequest->requestId; @@ -96,13 +96,13 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) { retrieveReq.showId = pRequest->body.showInfo.execId; int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq); - void* pReq = malloc(contLen); + void* pReq = taosMemoryMalloc(contLen); tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq); pMsgSendInfo->msgInfo.pData = pReq; pMsgSendInfo->msgInfo.len = contLen; pMsgSendInfo->msgInfo.handle = NULL; } else { - SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq)); + SVShowTablesFetchReq* pFetchMsg = taosMemoryCalloc(1, sizeof(SVShowTablesFetchReq)); if (pFetchMsg == NULL) { return NULL; } @@ -135,12 +135,12 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { tDeserializeSShowRsp(pMsg->pData, pMsg->len, &showRsp); STableMetaRsp *pMetaMsg = &showRsp.tableMeta; - tfree(pRequest->body.resInfo.pRspMsg); + taosMemoryFreeClear(pRequest->body.resInfo.pRspMsg); pRequest->body.resInfo.pRspMsg = pMsg->pData; SReqResultInfo* pResInfo = &pRequest->body.resInfo; if (pResInfo->fields == NULL) { - TAOS_FIELD* pFields = calloc(pMetaMsg->numOfColumns, sizeof(TAOS_FIELD)); + TAOS_FIELD* pFields = taosMemoryCalloc(pMetaMsg->numOfColumns, sizeof(TAOS_FIELD)); for (int32_t i = 0; i < pMetaMsg->numOfColumns; ++i) { SSchema* pSchema = &pMetaMsg->pSchemas[i]; tstrncpy(pFields[i].name, pSchema->name, tListLen(pFields[i].name)); @@ -171,7 +171,7 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj *pRequest = param; SReqResultInfo *pResInfo = &pRequest->body.resInfo; - tfree(pResInfo->pRspMsg); + taosMemoryFreeClear(pResInfo->pRspMsg); if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); @@ -204,7 +204,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; SReqResultInfo* pResInfo = &pRequest->body.resInfo; - tfree(pResInfo->pRspMsg); + taosMemoryFreeClear(pResInfo->pRspMsg); if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); @@ -237,7 +237,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { // todo rsp with the vnode id list SRequestObj* pRequest = param; - free(pMsg->pData); + taosMemoryFree(pMsg->pData); if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); } @@ -266,7 +266,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { } if (code != TSDB_CODE_SUCCESS) { - free(pMsg->pData); + taosMemoryFree(pMsg->pData); setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; @@ -284,7 +284,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { if (code != 0) { terrno = code; if (output.dbVgroup) taosHashCleanup(output.dbVgroup->vgHash); - tfree(output.dbVgroup); + taosMemoryFreeClear(output.dbVgroup); tscError("failed to build use db output since %s", terrstr()); } else { @@ -304,7 +304,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { tNameGetDbName(&name, db); setConnectionDB(pRequest->pTscObj, db); - free(pMsg->pData); + taosMemoryFree(pMsg->pData); tsem_post(&pRequest->body.rspSem); return 0; } @@ -313,7 +313,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { assert(pMsg != NULL && param != NULL); SRequestObj* pRequest = param; - free(pMsg->pData); + taosMemoryFree(pMsg->pData); if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 49fe7aa653..52d5400b0b 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -136,14 +136,14 @@ typedef struct { } SMqCommitCbParam; tmq_conf_t* tmq_conf_new() { - tmq_conf_t* conf = calloc(1, sizeof(tmq_conf_t)); + tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t)); conf->auto_commit = false; conf->resetOffset = TMQ_CONF__RESET_OFFSET__EARLIEAST; return conf; } void tmq_conf_destroy(tmq_conf_t* conf) { - if (conf) free(conf); + if (conf) taosMemoryFree(conf); } tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value) { @@ -184,7 +184,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } tmq_list_t* tmq_list_new() { - tmq_list_t* ptr = malloc(sizeof(tmq_list_t) + 8 * sizeof(char*)); + tmq_list_t* ptr = taosMemoryMalloc(sizeof(tmq_list_t) + 8 * sizeof(char*)); if (ptr == NULL) { return ptr; } @@ -254,7 +254,7 @@ tmq_resp_err_t tmq_unsubscribe(tmq_t* tmq) { } tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errstrLen) { - tmq_t* pTmq = calloc(sizeof(tmq_t), 1); + tmq_t* pTmq = taosMemoryCalloc(sizeof(tmq_t), 1); if (pTmq == NULL) { return NULL; } @@ -317,7 +317,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); tEncodeSMqCMCommitOffsetReq(&encoder, &req); int32_t tlen = encoder.pos; - void* buf = malloc(tlen); + void* buf = taosMemoryMalloc(tlen); if (buf == NULL) { tCoderClear(&encoder); return -1; @@ -333,7 +333,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in tscError("failed to malloc request"); } - SMqCommitCbParam* pParam = malloc(sizeof(SMqCommitCbParam)); + SMqCommitCbParam* pParam = taosMemoryMalloc(sizeof(SMqCommitCbParam)); if (pParam == NULL) { return -1; } @@ -361,7 +361,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in } tsem_destroy(&pParam->rspSem); - free(pParam); + taosMemoryFree(pParam); if (pArray) { taosArrayDestroy(pArray); @@ -394,7 +394,7 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) { tNameSetDbName(&name, tmq->pTscObj->acctId, dbName, strlen(dbName)); tNameFromString(&name, topicName, T_NAME_TABLE); - char* topicFname = calloc(1, TSDB_TOPIC_FNAME_LEN); + char* topicFname = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN); if (topicFname == NULL) { goto _return; } @@ -405,11 +405,11 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) { topic.vgs = taosArrayInit(0, sizeof(SMqClientVg)); taosArrayPush(tmq->clientTopics, &topic); taosArrayPush(req.topicNames, &topicFname); - free(dbName); + taosMemoryFree(dbName); } int tlen = tSerializeSCMSubscribeReq(NULL, &req); - void* buf = malloc(tlen); + void* buf = taosMemoryMalloc(tlen); if (buf == NULL) { goto _return; } @@ -508,7 +508,7 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa strcpy(req.outputSTbName, tbName); int tlen = tSerializeSCMCreateStreamReq(NULL, 0, &req); - void* buf = malloc(tlen); + void* buf = taosMemoryMalloc(tlen); if (buf == NULL) { goto _return; } @@ -532,7 +532,7 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa tsem_wait(&pRequest->body.rspSem); _return: - tfree(astStr); + taosMemoryFreeClear(astStr); qDestroyQuery(pQueryNode); /*if (sendInfo != NULL) {*/ /*destroySendMsgInfo(sendInfo);*/ @@ -594,7 +594,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i tNameExtractFullName(&name, req.name); int tlen = tSerializeSCMCreateTopicReq(NULL, 0, &req); - void* buf = malloc(tlen); + void* buf = taosMemoryMalloc(tlen); if (buf == NULL) { goto _return; } @@ -618,7 +618,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i tsem_wait(&pRequest->body.rspSem); _return: - tfree(astStr); + taosMemoryFreeClear(astStr); qDestroyQuery(pQueryNode); /*if (sendInfo != NULL) {*/ /*destroySendMsgInfo(sendInfo);*/ @@ -757,7 +757,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { #if 0 if (pParam->sync == 1) { - /**pParam->msg = malloc(sizeof(tmq_message_t));*/ + /**pParam->msg = taosMemoryMalloc(sizeof(tmq_message_t));*/ *pParam->msg = taosAllocateQitem(sizeof(tmq_message_t)); if (*pParam->msg) { memcpy(*pParam->msg, pMsg->pData, sizeof(SMqRspHead)); @@ -774,7 +774,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { } #endif - /*SMqConsumeRsp* pRsp = calloc(1, sizeof(SMqConsumeRsp));*/ + /*SMqConsumeRsp* pRsp = taosMemoryCalloc(1, sizeof(SMqConsumeRsp));*/ tmq_message_t* pRsp = taosAllocateQitem(sizeof(tmq_message_t)); if (pRsp == NULL) { goto WRITE_QUEUE_FAIL; @@ -884,7 +884,7 @@ END: int32_t tmqAskEp(tmq_t* tmq, bool sync) { int32_t tlen = sizeof(SMqCMGetSubEpReq); - SMqCMGetSubEpReq* req = malloc(tlen); + SMqCMGetSubEpReq* req = taosMemoryMalloc(tlen); if (req == NULL) { tscError("failed to malloc get subscribe ep buf"); return -1; @@ -893,21 +893,21 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { req->epoch = htonl(tmq->epoch); strcpy(req->cgroup, tmq->groupId); - SMqAskEpCbParam* pParam = malloc(sizeof(SMqAskEpCbParam)); + SMqAskEpCbParam* pParam = taosMemoryMalloc(sizeof(SMqAskEpCbParam)); if (pParam == NULL) { tscError("failed to malloc subscribe param"); - free(req); + taosMemoryFree(req); return -1; } pParam->tmq = tmq; pParam->sync = sync; tsem_init(&pParam->rspSem, 0, 0); - SMsgSendInfo* sendInfo = malloc(sizeof(SMsgSendInfo)); + SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo)); if (sendInfo == NULL) { tsem_destroy(&pParam->rspSem); - free(pParam); - free(req); + taosMemoryFree(pParam); + taosMemoryFree(req); return -1; } @@ -967,7 +967,7 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo reqOffset = tmq->resetOffsetCfg; } - SMqPollReq* pReq = malloc(sizeof(SMqPollReq)); + SMqPollReq* pReq = taosMemoryMalloc(sizeof(SMqPollReq)); if (pReq == NULL) { return NULL; } @@ -1003,7 +1003,7 @@ tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) { return NULL; } - SMqPollCbParam* pParam = malloc(sizeof(SMqPollCbParam)); + SMqPollCbParam* pParam = taosMemoryMalloc(sizeof(SMqPollCbParam)); if (pParam == NULL) { atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); // TODO: out of mem @@ -1016,7 +1016,7 @@ tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) { pParam->msg = &msg; tsem_init(&pParam->rspSem, 0, 0); - SMsgSendInfo* sendInfo = malloc(sizeof(SMsgSendInfo)); + SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo)); if (sendInfo == NULL) { return NULL; } @@ -1071,9 +1071,9 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { tsem_post(&tmq->rspSem); return -1; } - SMqPollCbParam* pParam = malloc(sizeof(SMqPollCbParam)); + SMqPollCbParam* pParam = taosMemoryMalloc(sizeof(SMqPollCbParam)); if (pParam == NULL) { - free(pReq); + taosMemoryFree(pReq); atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); tsem_post(&tmq->rspSem); return -1; @@ -1083,10 +1083,10 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { pParam->epoch = tmq->epoch; pParam->sync = 0; - SMsgSendInfo* sendInfo = malloc(sizeof(SMsgSendInfo)); + SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo)); if (sendInfo == NULL) { - free(pReq); - free(pParam); + taosMemoryFree(pReq); + taosMemoryFree(pParam); atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); tsem_post(&tmq->rspSem); return -1; @@ -1258,7 +1258,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { return NULL; } - SMqPollCbParam* param = malloc(sizeof(SMqPollCbParam)); + SMqPollCbParam* param = taosMemoryMalloc(sizeof(SMqPollCbParam)); if (param == NULL) { ASSERT(false); taosMsleep(blocking_time); @@ -1289,7 +1289,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { tsem_wait(¶m->rspSem); tsem_destroy(¶m->rspSem); - free(param); + taosMemoryFree(param); if (tmq_message == NULL) { if (beginVgIdx == pTopic->nextVgIdx) { @@ -1331,7 +1331,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* tmq_topic_v SRequestObj* pRequest = createRequest(tmq->pTscObj, NULL, NULL, TDMT_VND_CONSUME); pRequest->body.requestMsg = (SDataBuf){.pData = pReq, .len = sizeof(SMqConsumeReq)}; - SMqCommitCbParam* pParam = malloc(sizeof(SMqCommitCbParam)); + SMqCommitCbParam* pParam = taosMemoryMalloc(sizeof(SMqCommitCbParam)); if (pParam == NULL) { continue; } @@ -1360,7 +1360,7 @@ void tmq_message_destroy(tmq_message_t* tmq_message) { if (tmq_message == NULL) return; SMqPollRsp* pRsp = &tmq_message->msg; tDeleteSMqConsumeRsp(pRsp); - /*free(tmq_message);*/ + /*taosMemoryFree(tmq_message);*/ taosFreeQitem(tmq_message); } @@ -1403,7 +1403,7 @@ char* tmq_get_topic_name(tmq_message_t* message) { return "not implemented yet"; #if 0 tmq_t* tmqCreateConsumerImpl(TAOS* conn, tmq_conf_t* conf) { - tmq_t* pTmq = malloc(sizeof(tmq_t)); + tmq_t* pTmq = taosMemoryMalloc(sizeof(tmq_t)); if (pTmq == NULL) { return NULL; } @@ -1417,7 +1417,7 @@ tmq_t* tmqCreateConsumerImpl(TAOS* conn, tmq_conf_t* conf) { static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { assert(pMsgBody != NULL); - tfree(pMsgBody->msgInfo.pData); - tfree(pMsgBody); + taosMemoryFreeClear(pMsgBody->msgInfo.pData); + taosMemoryFreeClear(pMsgBody); } #endif diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index afdd8f155f..2aeaad5a38 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -115,7 +115,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con newSize = newSize * 1.5; } - char* buf = realloc(pColumnInfoData->pData, newSize); + char* buf = taosMemoryRealloc(pColumnInfoData->pData, newSize); if (buf == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -178,7 +178,7 @@ static void doBitmapMerge(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, c uint32_t total = numOfRow1 + numOfRow2; if (BitmapLen(numOfRow1) < BitmapLen(total)) { - char* tmp = realloc(pColumnInfoData->nullbitmap, BitmapLen(total)); + char* tmp = taosMemoryRealloc(pColumnInfoData->nullbitmap, BitmapLen(total)); uint32_t extend = BitmapLen(total) - BitmapLen(numOfRow1); memset(tmp + BitmapLen(numOfRow1), 0, extend); pColumnInfoData->nullbitmap = tmp; @@ -218,7 +218,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { // Handle the bitmap - char* p = realloc(pColumnInfoData->varmeta.offset, sizeof(int32_t) * (numOfRow1 + numOfRow2)); + char* p = taosMemoryRealloc(pColumnInfoData->varmeta.offset, sizeof(int32_t) * (numOfRow1 + numOfRow2)); if (p == NULL) { // TODO } @@ -232,7 +232,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co uint32_t len = pSource->varmeta.length; uint32_t oldLen = pColumnInfoData->varmeta.length; if (pColumnInfoData->varmeta.allocLen < len + oldLen) { - char* tmp = realloc(pColumnInfoData->pData, len + oldLen); + char* tmp = taosMemoryRealloc(pColumnInfoData->pData, len + oldLen); if (tmp == NULL) { return TSDB_CODE_VND_OUT_OF_MEMORY; } @@ -247,7 +247,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co doBitmapMerge(pColumnInfoData, numOfRow1, pSource, numOfRow2); int32_t newSize = (numOfRow1 + numOfRow2) * pColumnInfoData->info.bytes; - char* tmp = realloc(pColumnInfoData->pData, newSize); + char* tmp = taosMemoryRealloc(pColumnInfoData->pData, newSize); if (tmp == NULL) { return TSDB_CODE_VND_OUT_OF_MEMORY; } @@ -268,7 +268,7 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { // Handle the bitmap - char* p = realloc(pColumnInfoData->varmeta.offset, sizeof(int32_t) * numOfRows); + char* p = taosMemoryRealloc(pColumnInfoData->varmeta.offset, sizeof(int32_t) * numOfRows); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -277,7 +277,7 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p memcpy(pColumnInfoData->varmeta.offset, pSource->varmeta.offset, sizeof(int32_t) * numOfRows); if (pColumnInfoData->varmeta.allocLen < pSource->varmeta.length) { - char* tmp = realloc(pColumnInfoData->pData, pSource->varmeta.length); + char* tmp = taosMemoryRealloc(pColumnInfoData->pData, pSource->varmeta.length); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -289,7 +289,7 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p memcpy(pColumnInfoData->pData, pSource->pData, pSource->varmeta.length); pColumnInfoData->varmeta.length = pSource->varmeta.length; } else { - char* tmp = realloc(pColumnInfoData->nullbitmap, BitmapLen(numOfRows)); + char* tmp = taosMemoryRealloc(pColumnInfoData->nullbitmap, BitmapLen(numOfRows)); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -298,7 +298,7 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p memcpy(pColumnInfoData->nullbitmap, pSource->nullbitmap, BitmapLen(numOfRows)); int32_t newSize = numOfRows * pColumnInfoData->info.bytes; - tmp = realloc(pColumnInfoData->pData, newSize); + tmp = taosMemoryRealloc(pColumnInfoData->pData, newSize); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -349,7 +349,7 @@ int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) { uint32_t newLen = colDataGetLength(pCol1, pSrc->info.rows); int32_t newSize = oldLen + newLen; - char* tmp = realloc(pCol2->pData, newSize); + char* tmp = taosMemoryRealloc(pCol2->pData, newSize); if (tmp != NULL) { pCol2->pData = tmp; colDataMergeCol(pCol2, pDest->info.rows, pCol1, pSrc->info.rows); @@ -453,7 +453,7 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3 return NULL; } - SSDataBlock* pDst = calloc(1, sizeof(SSDataBlock)); + SSDataBlock* pDst = taosMemoryCalloc(1, sizeof(SSDataBlock)); if (pDst == NULL) { return NULL; } @@ -470,10 +470,10 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3 if (IS_VAR_DATA_TYPE(pSrcCol->info.type)) { SVarColAttr* pAttr = &colInfo.varmeta; - pAttr->offset = calloc(rowCount, sizeof(int32_t)); + pAttr->offset = taosMemoryCalloc(rowCount, sizeof(int32_t)); } else { - colInfo.nullbitmap = calloc(1, BitmapLen(rowCount)); - colInfo.pData = calloc(rowCount, colInfo.info.bytes); + colInfo.nullbitmap = taosMemoryCalloc(1, BitmapLen(rowCount)); + colInfo.pData = taosMemoryCalloc(rowCount, colInfo.info.bytes); } taosArrayPush(pDst->pDataBlock, &colInfo); @@ -562,7 +562,7 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) { if (IS_VAR_DATA_TYPE(pCol->info.type)) { if (pCol->varmeta.allocLen < colLength) { - char* tmp = realloc(pCol->pData, colLength); + char* tmp = taosMemoryRealloc(pCol->pData, colLength); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -610,7 +610,7 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) { } SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols) { - SSchema* pSchema = calloc(pBlock->info.numOfCols, sizeof(SSchema)); + SSchema* pSchema = taosMemoryCalloc(pBlock->info.numOfCols, sizeof(SSchema)); for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); pSchema[i].bytes = pColInfoData->info.bytes; @@ -819,7 +819,7 @@ static SColumnInfoData* createHelpColInfoData(const SSDataBlock* pDataBlock) { int32_t rows = pDataBlock->info.rows; int32_t numOfCols = pDataBlock->info.numOfCols; - SColumnInfoData* pCols = calloc(numOfCols, sizeof(SColumnInfoData)); + SColumnInfoData* pCols = taosMemoryCalloc(numOfCols, sizeof(SColumnInfoData)); if (pCols == NULL) { return NULL; } @@ -829,14 +829,14 @@ static SColumnInfoData* createHelpColInfoData(const SSDataBlock* pDataBlock) { pCols[i].info = pColInfoData->info; if (IS_VAR_DATA_TYPE(pCols[i].info.type)) { - pCols[i].varmeta.offset = calloc(rows, sizeof(int32_t)); - pCols[i].pData = calloc(1, pColInfoData->varmeta.length); + pCols[i].varmeta.offset = taosMemoryCalloc(rows, sizeof(int32_t)); + pCols[i].pData = taosMemoryCalloc(1, pColInfoData->varmeta.length); pCols[i].varmeta.length = pColInfoData->varmeta.length; pCols[i].varmeta.allocLen = pCols[i].varmeta.length; } else { - pCols[i].nullbitmap = calloc(1, BitmapLen(rows)); - pCols[i].pData = calloc(rows, pCols[i].info.bytes); + pCols[i].nullbitmap = taosMemoryCalloc(1, BitmapLen(rows)); + pCols[i].pData = taosMemoryCalloc(rows, pCols[i].info.bytes); } } @@ -851,22 +851,22 @@ static void copyBackToBlock(SSDataBlock* pDataBlock, SColumnInfoData* pCols) { pColInfoData->info = pCols[i].info; if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - tfree(pColInfoData->varmeta.offset); + taosMemoryFreeClear(pColInfoData->varmeta.offset); pColInfoData->varmeta = pCols[i].varmeta; } else { - tfree(pColInfoData->nullbitmap); + taosMemoryFreeClear(pColInfoData->nullbitmap); pColInfoData->nullbitmap = pCols[i].nullbitmap; } - tfree(pColInfoData->pData); + taosMemoryFreeClear(pColInfoData->pData); pColInfoData->pData = pCols[i].pData; } - tfree(pCols); + taosMemoryFreeClear(pCols); } static int32_t* createTupleIndex(size_t rows) { - int32_t* index = calloc(rows, sizeof(int32_t)); + int32_t* index = taosMemoryCalloc(rows, sizeof(int32_t)); if (index == NULL) { return NULL; } @@ -878,7 +878,7 @@ static int32_t* createTupleIndex(size_t rows) { return index; } -static void destroyTupleIndex(int32_t* index) { tfree(index); } +static void destroyTupleIndex(int32_t* index) { taosMemoryFreeClear(index); } static __compar_fn_t getComparFn(int32_t type, int32_t order) { switch (type) { @@ -1019,8 +1019,8 @@ SHelper* createTupleIndex_rv(int32_t numOfRows, SArray* pOrderInfo, SSDataBlock* size_t len = sortValLengthPerRow * pBlock->info.rows; - char* buf = calloc(1, len); - SHelper* phelper = calloc(numOfRows, sizeof(SHelper)); + char* buf = taosMemoryCalloc(1, len); + SHelper* phelper = taosMemoryCalloc(numOfRows, sizeof(SHelper)); for (int32_t i = 0; i < numOfRows; ++i) { phelper[i].index = i; phelper[i].pData = buf + sortValLengthPerRow * i; @@ -1163,7 +1163,7 @@ int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRo } if (IS_VAR_DATA_TYPE(pColumn->info.type)) { - char* tmp = realloc(pColumn->varmeta.offset, sizeof(int32_t) * numOfRows); + char* tmp = taosMemoryRealloc(pColumn->varmeta.offset, sizeof(int32_t) * numOfRows); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1173,9 +1173,9 @@ int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRo pColumn->varmeta.length = 0; pColumn->varmeta.allocLen = 0; - tfree(pColumn->pData); + taosMemoryFreeClear(pColumn->pData); } else { - char* tmp = realloc(pColumn->nullbitmap, BitmapLen(numOfRows)); + char* tmp = taosMemoryRealloc(pColumn->nullbitmap, BitmapLen(numOfRows)); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1183,7 +1183,7 @@ int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRo pColumn->nullbitmap = tmp; memset(pColumn->nullbitmap, 0, BitmapLen(numOfRows)); assert(pColumn->info.bytes); - tmp = realloc(pColumn->pData, numOfRows * pColumn->info.bytes); + tmp = taosMemoryRealloc(pColumn->pData, numOfRows * pColumn->info.bytes); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1214,14 +1214,14 @@ void* blockDataDestroy(SSDataBlock* pBlock) { } blockDestroyInner(pBlock); - tfree(pBlock); + taosMemoryFreeClear(pBlock); return NULL; } SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) { int32_t numOfCols = pDataBlock->info.numOfCols; - SSDataBlock* pBlock = calloc(1, sizeof(SSDataBlock)); + SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); pBlock->info.numOfCols = numOfCols; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index ed5441fe99..5b27fd01f4 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -37,7 +37,7 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { #endif if (pCol->spaceSize < spaceNeeded) { - void *ptr = realloc(pCol->pData, spaceNeeded); + void *ptr = taosMemoryRealloc(pCol->pData, spaceNeeded); if (ptr == NULL) { uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)spaceNeeded, strerror(errno)); return -1; @@ -66,7 +66,7 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { */ STSchema *tdDupSchema(const STSchema *pSchema) { int tlen = sizeof(STSchema) + sizeof(STColumn) * schemaNCols(pSchema); - STSchema *tSchema = (STSchema *)malloc(tlen); + STSchema *tSchema = (STSchema *)taosMemoryMalloc(tlen); if (tSchema == NULL) return NULL; memcpy((void *)tSchema, (void *)pSchema, tlen); @@ -127,7 +127,7 @@ int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) { if (pBuilder == NULL) return -1; pBuilder->tCols = 256; - pBuilder->columns = (STColumn *)malloc(sizeof(STColumn) * pBuilder->tCols); + pBuilder->columns = (STColumn *)taosMemoryMalloc(sizeof(STColumn) * pBuilder->tCols); if (pBuilder->columns == NULL) return -1; tdResetTSchemaBuilder(pBuilder, version); @@ -136,7 +136,7 @@ int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) { void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder) { if (pBuilder) { - tfree(pBuilder->columns); + taosMemoryFreeClear(pBuilder->columns); } } @@ -153,7 +153,7 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int1 if (pBuilder->nCols >= pBuilder->tCols) { pBuilder->tCols *= 2; - STColumn *columns = (STColumn *)realloc(pBuilder->columns, sizeof(STColumn) * pBuilder->tCols); + STColumn *columns = (STColumn *)taosMemoryRealloc(pBuilder->columns, sizeof(STColumn) * pBuilder->tCols); if (columns == NULL) return -1; pBuilder->columns = columns; } @@ -191,7 +191,7 @@ STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder) { int tlen = sizeof(STSchema) + sizeof(STColumn) * pBuilder->nCols; - STSchema *pSchema = (STSchema *)malloc(tlen); + STSchema *pSchema = (STSchema *)taosMemoryMalloc(tlen); if (pSchema == NULL) return NULL; schemaVersion(pSchema) = pBuilder->version; @@ -221,7 +221,7 @@ void tdInitDataRow(SDataRow row, STSchema *pSchema) { SDataRow tdNewDataRowFromSchema(STSchema *pSchema) { int32_t size = dataRowMaxBytesFromSchema(pSchema); - SDataRow row = malloc(size); + SDataRow row = taosMemoryMalloc(size); if (row == NULL) return NULL; tdInitDataRow(row, pSchema); @@ -232,11 +232,11 @@ SDataRow tdNewDataRowFromSchema(STSchema *pSchema) { * Free the SDataRow object */ void tdFreeDataRow(SDataRow row) { - if (row) free(row); + if (row) taosMemoryFree(row); } SDataRow tdDataRowDup(SDataRow row) { - SDataRow trow = malloc(dataRowLen(row)); + SDataRow trow = taosMemoryMalloc(dataRowLen(row)); if (trow == NULL) return NULL; dataRowCpy(trow, row); @@ -244,7 +244,7 @@ SDataRow tdDataRowDup(SDataRow row) { } SMemRow tdMemRowDup(SMemRow row) { - SMemRow trow = malloc(memRowTLen(row)); + SMemRow trow = taosMemoryMalloc(memRowTLen(row)); if (trow == NULL) return NULL; memRowCpy(trow, row); @@ -348,7 +348,7 @@ void *dataColSetOffset(SDataCol *pCol, int nEle) { } SDataCols *tdNewDataCols(int maxCols, int maxRows) { - SDataCols *pCols = (SDataCols *)calloc(1, sizeof(SDataCols)); + SDataCols *pCols = (SDataCols *)taosMemoryCalloc(1, sizeof(SDataCols)); if (pCols == NULL) { uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)sizeof(SDataCols), strerror(errno)); return NULL; @@ -360,7 +360,7 @@ SDataCols *tdNewDataCols(int maxCols, int maxRows) { pCols->numOfCols = 0; if (maxCols > 0) { - pCols->cols = (SDataCol *)calloc(maxCols, sizeof(SDataCol)); + pCols->cols = (SDataCol *)taosMemoryCalloc(maxCols, sizeof(SDataCol)); if (pCols->cols == NULL) { uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)sizeof(SDataCol) * maxCols, strerror(errno)); @@ -384,7 +384,7 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { int oldMaxCols = pCols->maxCols; if (schemaNCols(pSchema) > oldMaxCols) { pCols->maxCols = schemaNCols(pSchema); - void *ptr = (SDataCol *)realloc(pCols->cols, sizeof(SDataCol) * pCols->maxCols); + void *ptr = (SDataCol *)taosMemoryRealloc(pCols->cols, sizeof(SDataCol) * pCols->maxCols); if (ptr == NULL) return -1; pCols->cols = ptr; for (i = oldMaxCols; i < pCols->maxCols; i++) { @@ -411,12 +411,12 @@ SDataCols *tdFreeDataCols(SDataCols *pCols) { int maxCols = pCols->maxCols; for (i = 0; i < maxCols; i++) { SDataCol *pCol = &pCols->cols[i]; - tfree(pCol->pData); + taosMemoryFreeClear(pCol->pData); } - free(pCols->cols); + taosMemoryFree(pCols->cols); pCols->cols = NULL; } - free(pCols); + taosMemoryFree(pCols); } return NULL; } @@ -641,7 +641,7 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i #endif SKVRow tdKVRowDup(SKVRow row) { - SKVRow trow = malloc(kvRowLen(row)); + SKVRow trow = taosMemoryMalloc(kvRowLen(row)); if (trow == NULL) return NULL; kvRowCpy(trow, row); @@ -674,7 +674,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { int oRowCols = kvRowNCols(row); ASSERT(diff > 0); - nrow = malloc(nRowLen); + nrow = taosMemoryMalloc(nRowLen); if (nrow == NULL) return -1; kvRowSetLen(nrow, nRowLen); @@ -692,7 +692,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { tdSortKVRowByColIdx(nrow); *orow = nrow; - free(row); + taosMemoryFree(row); } else { ASSERT(((SColIdx *)ptr)->colId == colId); if (IS_VAR_DATA_TYPE(type)) { @@ -703,7 +703,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { } else { // need to reallocate the memory int16_t nlen = kvRowLen(row) + (varDataTLen(value) - varDataTLen(pOldVal)); ASSERT(nlen > 0); - nrow = malloc(nlen); + nrow = taosMemoryMalloc(nlen); if (nrow == NULL) return -1; kvRowSetLen(nrow, nlen); @@ -728,7 +728,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { } *orow = nrow; - free(row); + taosMemoryFree(row); } } else { memcpy(kvRowColVal(row, (SColIdx *)ptr), value, TYPE_BYTES[type]); @@ -757,21 +757,21 @@ void *tdDecodeKVRow(void *buf, SKVRow *row) { int tdInitKVRowBuilder(SKVRowBuilder *pBuilder) { pBuilder->tCols = 128; pBuilder->nCols = 0; - pBuilder->pColIdx = (SColIdx *)malloc(sizeof(SColIdx) * pBuilder->tCols); + pBuilder->pColIdx = (SColIdx *)taosMemoryMalloc(sizeof(SColIdx) * pBuilder->tCols); if (pBuilder->pColIdx == NULL) return -1; pBuilder->alloc = 1024; pBuilder->size = 0; - pBuilder->buf = malloc(pBuilder->alloc); + pBuilder->buf = taosMemoryMalloc(pBuilder->alloc); if (pBuilder->buf == NULL) { - free(pBuilder->pColIdx); + taosMemoryFree(pBuilder->pColIdx); return -1; } return 0; } void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder) { - tfree(pBuilder->pColIdx); - tfree(pBuilder->buf); + taosMemoryFreeClear(pBuilder->pColIdx); + taosMemoryFreeClear(pBuilder->buf); } void tdResetKVRowBuilder(SKVRowBuilder *pBuilder) { @@ -785,7 +785,7 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) { tlen += TD_KV_ROW_HEAD_SIZE; - SKVRow row = malloc(tlen); + SKVRow row = taosMemoryMalloc(tlen); if (row == NULL) return NULL; kvRowSetNCols(row, pBuilder->nCols); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 09b790e73d..d7df3e115f 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -371,7 +371,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { case TD_SUPER_TABLE: buf = taosDecodeFixedI64(buf, &(pReq->stbCfg.suid)); buf = taosDecodeFixedU32(buf, &(pReq->stbCfg.nCols)); - pReq->stbCfg.pSchema = (SSchema *)malloc(pReq->stbCfg.nCols * sizeof(SSchema)); + pReq->stbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nCols * sizeof(SSchema)); for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) { buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type)); buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].colId)); @@ -379,7 +379,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeStringTo(buf, pReq->stbCfg.pSchema[i].name); } buf = taosDecodeFixedU32(buf, &pReq->stbCfg.nTagCols); - pReq->stbCfg.pTagSchema = (SSchema *)malloc(pReq->stbCfg.nTagCols * sizeof(SSchema)); + pReq->stbCfg.pTagSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nTagCols * sizeof(SSchema)); for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) { buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type)); buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].colId); @@ -388,7 +388,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { } buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); if (pReq->stbCfg.nBSmaCols > 0) { - pReq->stbCfg.pBSmaCols = (col_id_t *)malloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); + pReq->stbCfg.pBSmaCols = (col_id_t *)taosMemoryMalloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); } @@ -396,7 +396,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { pReq->stbCfg.pBSmaCols = NULL; } if (pReq->rollup) { - pReq->stbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); + pReq->stbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam)); SRSmaParam *param = pReq->stbCfg.pRSmaParam; buf = taosDecodeFixedU32(buf, (uint32_t *)¶m->xFilesFactor); buf = taosDecodeFixedI8(buf, ¶m->delayUnit); @@ -419,7 +419,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { break; case TD_NORMAL_TABLE: buf = taosDecodeFixedU32(buf, &pReq->ntbCfg.nCols); - pReq->ntbCfg.pSchema = (SSchema *)malloc(pReq->ntbCfg.nCols * sizeof(SSchema)); + pReq->ntbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->ntbCfg.nCols * sizeof(SSchema)); for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) { buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type); buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].colId); @@ -428,7 +428,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { } buf = taosDecodeFixedI16(buf, &(pReq->ntbCfg.nBSmaCols)); if (pReq->ntbCfg.nBSmaCols > 0) { - pReq->ntbCfg.pBSmaCols = (col_id_t *)malloc(pReq->ntbCfg.nBSmaCols * sizeof(col_id_t)); + pReq->ntbCfg.pBSmaCols = (col_id_t *)taosMemoryMalloc(pReq->ntbCfg.nBSmaCols * sizeof(col_id_t)); for (col_id_t i = 0; i < pReq->ntbCfg.nBSmaCols; ++i) { buf = taosDecodeFixedI16(buf, pReq->ntbCfg.pBSmaCols + i); } @@ -436,7 +436,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { pReq->ntbCfg.pBSmaCols = NULL; } if (pReq->rollup) { - pReq->ntbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); + pReq->ntbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam)); SRSmaParam *param = pReq->ntbCfg.pRSmaParam; buf = taosDecodeFixedU32(buf, (uint32_t *)¶m->xFilesFactor); buf = taosDecodeFixedI8(buf, ¶m->delayUnit); @@ -608,7 +608,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR } if (pReq->commentLen > 0) { - pReq->comment = malloc(pReq->commentLen); + pReq->comment = taosMemoryMalloc(pReq->commentLen); if (pReq->comment == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; } @@ -623,7 +623,7 @@ void tFreeSMCreateStbReq(SMCreateStbReq *pReq) { taosArrayDestroy(pReq->pColumns); taosArrayDestroy(pReq->pTags); taosArrayDestroy(pReq->pSmas); - tfree(pReq->comment); + taosMemoryFreeClear(pReq->comment); pReq->pColumns = NULL; pReq->pTags = NULL; pReq->pSmas = NULL; @@ -770,22 +770,22 @@ int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pR if (tDecodeI32(&decoder, &pReq->sqlLen) < 0) return -1; if (tDecodeI32(&decoder, &pReq->astLen) < 0) return -1; if (pReq->exprLen > 0) { - pReq->expr = malloc(pReq->exprLen); + pReq->expr = taosMemoryMalloc(pReq->exprLen); if (pReq->expr == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->expr) < 0) return -1; } if (pReq->tagsFilterLen > 0) { - pReq->tagsFilter = malloc(pReq->tagsFilterLen); + pReq->tagsFilter = taosMemoryMalloc(pReq->tagsFilterLen); if (pReq->tagsFilter == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->tagsFilter) < 0) return -1; } if (pReq->sqlLen > 0) { - pReq->sql = malloc(pReq->sqlLen); + pReq->sql = taosMemoryMalloc(pReq->sqlLen); if (pReq->sql == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1; } if (pReq->astLen > 0) { - pReq->ast = malloc(pReq->astLen); + pReq->ast = taosMemoryMalloc(pReq->astLen); if (pReq->ast == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1; } @@ -796,10 +796,10 @@ int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pR } void tFreeSMCreateSmaReq(SMCreateSmaReq *pReq) { - tfree(pReq->expr); - tfree(pReq->tagsFilter); - tfree(pReq->sql); - tfree(pReq->ast); + taosMemoryFreeClear(pReq->expr); + taosMemoryFreeClear(pReq->tagsFilter); + taosMemoryFreeClear(pReq->sql); + taosMemoryFreeClear(pReq->ast); } int32_t tSerializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropSmaReq *pReq) { @@ -1987,7 +1987,7 @@ int32_t tDeserializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) { if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; if (tDecodeI32(&decoder, &pReq->payloadLen) < 0) return -1; if (pReq->payloadLen > 0) { - pReq->payload = malloc(pReq->payloadLen); + pReq->payload = taosMemoryMalloc(pReq->payloadLen); if (pReq->payload == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->payload) < 0) return -1; } @@ -1997,7 +1997,7 @@ int32_t tDeserializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) { return 0; } -void tFreeSShowReq(SShowReq *pReq) { tfree(pReq->payload); } +void tFreeSShowReq(SShowReq *pReq) { taosMemoryFreeClear(pReq->payload); } int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq *pReq) { SCoder encoder = {0}; @@ -2071,7 +2071,7 @@ static int32_t tDecodeSTableMetaRsp(SCoder *pDecoder, STableMetaRsp *pRsp) { if (tDecodeI32(pDecoder, &pRsp->vgId) < 0) return -1; int32_t totalCols = pRsp->numOfTags + pRsp->numOfColumns; - pRsp->pSchemas = malloc(sizeof(SSchema) * totalCols); + pRsp->pSchemas = taosMemoryMalloc(sizeof(SSchema) * totalCols); if (pRsp->pSchemas == NULL) return -1; for (int32_t i = 0; i < totalCols; ++i) { @@ -2152,7 +2152,7 @@ int32_t tDeserializeSTableMetaBatchRsp(void *buf, int32_t bufLen, STableMetaBatc return 0; } -void tFreeSTableMetaRsp(STableMetaRsp *pRsp) { tfree(pRsp->pSchemas); } +void tFreeSTableMetaRsp(STableMetaRsp *pRsp) { taosMemoryFreeClear(pRsp->pSchemas); } void tFreeSTableMetaBatchRsp(STableMetaBatchRsp *pRsp) { int32_t numOfBatch = taosArrayGetSize(pRsp->pArray); @@ -2304,13 +2304,13 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR if (tDecodeI32(&decoder, &astLen) < 0) return -1; if (sqlLen > 0) { - pReq->sql = calloc(1, sqlLen + 1); + pReq->sql = taosMemoryCalloc(1, sqlLen + 1); if (pReq->sql == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1; } if (astLen > 0) { - pReq->ast = calloc(1, astLen + 1); + pReq->ast = taosMemoryCalloc(1, astLen + 1); if (pReq->ast == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1; } @@ -2322,8 +2322,8 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR } void tFreeSCMCreateTopicReq(SCMCreateTopicReq *pReq) { - tfree(pReq->sql); - tfree(pReq->ast); + taosMemoryFreeClear(pReq->sql); + taosMemoryFreeClear(pReq->ast); } int32_t tSerializeSCMCreateTopicRsp(void *buf, int32_t bufLen, const SCMCreateTopicRsp *pRsp) { @@ -3074,13 +3074,13 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea if (tDecodeI32(&decoder, &astLen) < 0) return -1; if (sqlLen > 0) { - pReq->sql = calloc(1, sqlLen + 1); + pReq->sql = taosMemoryCalloc(1, sqlLen + 1); if (pReq->sql == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1; } if (astLen > 0) { - pReq->ast = calloc(1, astLen + 1); + pReq->ast = taosMemoryCalloc(1, astLen + 1); if (pReq->ast == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1; } @@ -3091,6 +3091,6 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea } void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) { - tfree(pReq->sql); - tfree(pReq->ast); + taosMemoryFreeClear(pReq->sql); + taosMemoryFreeClear(pReq->ast); } diff --git a/source/common/src/tname.c b/source/common/src/tname.c index 5561eb93c3..f4755f5b5e 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -30,13 +30,13 @@ SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFil return NULL; } - SColumnFilterInfo* pFilter = calloc(1, numOfFilters * sizeof(SColumnFilterInfo)); + SColumnFilterInfo* pFilter = taosMemoryCalloc(1, numOfFilters * sizeof(SColumnFilterInfo)); memcpy(pFilter, src, sizeof(SColumnFilterInfo) * numOfFilters); for (int32_t j = 0; j < numOfFilters; ++j) { if (pFilter[j].filterstr) { size_t len = (size_t) pFilter[j].len + 1 * TSDB_NCHAR_SIZE; - pFilter[j].pz = (int64_t) calloc(1, len); + pFilter[j].pz = (int64_t) taosMemoryCalloc(1, len); memcpy((char*)pFilter[j].pz, (char*)src[j].pz, (size_t) pFilter[j].len); } @@ -171,7 +171,7 @@ bool tNameIsValid(const SName* name) { SName* tNameDup(const SName* name) { assert(name != NULL); - SName* p = malloc(sizeof(SName)); + SName* p = taosMemoryMalloc(sizeof(SName)); memcpy(p, name, sizeof(SName)); return p; } diff --git a/source/common/src/trow.c b/source/common/src/trow.c index 48a63799f5..9ee2ec1300 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -119,7 +119,7 @@ int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) { #endif STSRow *tdRowDup(STSRow *row) { - STSRow *trow = malloc(TD_ROW_LEN(row)); + STSRow *trow = taosMemoryMalloc(TD_ROW_LEN(row)); if (trow == NULL) return NULL; tdRowCpy(trow, row); diff --git a/source/common/src/ttszip.c b/source/common/src/ttszip.c index 5f0a353226..15e741d307 100644 --- a/source/common/src/ttszip.c +++ b/source/common/src/ttszip.c @@ -30,7 +30,7 @@ static int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader); * @return */ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { - STSBuf* pTSBuf = calloc(1, sizeof(STSBuf)); + STSBuf* pTSBuf = taosMemoryCalloc(1, sizeof(STSBuf)); if (pTSBuf == NULL) { return NULL; } @@ -41,7 +41,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { // pTSBuf->pFile = fopen(pTSBuf->path, "wb+"); pTSBuf->pFile = taosOpenFile(pTSBuf->path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC); if (pTSBuf->pFile == NULL) { - free(pTSBuf); + taosMemoryFree(pTSBuf); return NULL; } @@ -66,7 +66,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { } STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { - STSBuf* pTSBuf = calloc(1, sizeof(STSBuf)); + STSBuf* pTSBuf = taosMemoryCalloc(1, sizeof(STSBuf)); if (pTSBuf == NULL) { return NULL; } @@ -78,7 +78,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { // pTSBuf->pFile = fopen(pTSBuf->path, "rb+"); pTSBuf->pFile = taosOpenFile(pTSBuf->path, TD_FILE_WRITE | TD_FILE_READ); if (pTSBuf->pFile == NULL) { - free(pTSBuf); + taosMemoryFree(pTSBuf); return NULL; } @@ -101,7 +101,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { if (header.numOfGroup > pTSBuf->numOfAlloc) { pTSBuf->numOfAlloc = header.numOfGroup; - STSGroupBlockInfoEx* tmp = realloc(pTSBuf->pData, sizeof(STSGroupBlockInfoEx) * pTSBuf->numOfAlloc); + STSGroupBlockInfoEx* tmp = taosMemoryRealloc(pTSBuf->pData, sizeof(STSGroupBlockInfoEx) * pTSBuf->numOfAlloc); if (tmp == NULL) { tsBufDestroy(pTSBuf); return NULL; @@ -122,7 +122,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { size_t infoSize = sizeof(STSGroupBlockInfo) * pTSBuf->numOfGroups; - STSGroupBlockInfo* buf = (STSGroupBlockInfo*)calloc(1, infoSize); + STSGroupBlockInfo* buf = (STSGroupBlockInfo*)taosMemoryCalloc(1, infoSize); if (buf == NULL) { tsBufDestroy(pTSBuf); return NULL; @@ -137,7 +137,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { STSGroupBlockInfoEx* pBlockList = &pTSBuf->pData[i]; memcpy(&pBlockList->info, &buf[i], sizeof(STSGroupBlockInfo)); } - free(buf); + taosMemoryFree(buf); ret = taosLSeekFile(pTSBuf->pFile, 0, SEEK_END); UNUSED(ret); @@ -166,11 +166,11 @@ void* tsBufDestroy(STSBuf* pTSBuf) { return NULL; } - tfree(pTSBuf->assistBuf); - tfree(pTSBuf->tsData.rawBuf); + taosMemoryFreeClear(pTSBuf->assistBuf); + taosMemoryFreeClear(pTSBuf->tsData.rawBuf); - tfree(pTSBuf->pData); - tfree(pTSBuf->block.payload); + taosMemoryFreeClear(pTSBuf->pData); + taosMemoryFreeClear(pTSBuf->block.payload); if (!pTSBuf->remainOpen) { taosCloseFile(&pTSBuf->pFile); @@ -184,7 +184,7 @@ void* tsBufDestroy(STSBuf* pTSBuf) { } taosVariantDestroy(&pTSBuf->block.tag); - free(pTSBuf); + taosMemoryFree(pTSBuf); return NULL; } @@ -200,7 +200,7 @@ static STSGroupBlockInfoEx* addOneGroupInfo(STSBuf* pTSBuf, int32_t id) { uint32_t newSize = (uint32_t)(pTSBuf->numOfAlloc * 1.5); assert((int32_t)newSize > pTSBuf->numOfAlloc); - STSGroupBlockInfoEx* tmp = (STSGroupBlockInfoEx*)realloc(pTSBuf->pData, sizeof(STSGroupBlockInfoEx) * newSize); + STSGroupBlockInfoEx* tmp = (STSGroupBlockInfoEx*)taosMemoryRealloc(pTSBuf->pData, sizeof(STSGroupBlockInfoEx) * newSize); if (tmp == NULL) { return NULL; } @@ -240,7 +240,7 @@ static STSGroupBlockInfoEx* addOneGroupInfo(STSBuf* pTSBuf, int32_t id) { static void shrinkBuffer(STSList* ptsData) { // shrink tmp buffer size if it consumes too many memory compared to the pre-defined size if (ptsData->allocSize >= ptsData->threshold * 2) { - char* rawBuf = realloc(ptsData->rawBuf, MEM_BUF_SIZE); + char* rawBuf = taosMemoryRealloc(ptsData->rawBuf, MEM_BUF_SIZE); if (rawBuf) { ptsData->rawBuf = rawBuf; ptsData->allocSize = MEM_BUF_SIZE; @@ -322,7 +322,7 @@ static void writeDataToDisk(STSBuf* pTSBuf) { static void expandBuffer(STSList* ptsData, int32_t inputSize) { if (ptsData->allocSize - ptsData->len < inputSize) { int32_t newSize = inputSize + ptsData->len; - char* tmp = realloc(ptsData->rawBuf, (size_t)newSize); + char* tmp = taosMemoryRealloc(ptsData->rawBuf, (size_t)newSize); if (tmp == NULL) { // todo } @@ -366,7 +366,7 @@ STSBlock* readDataFromDisk(STSBuf* pTSBuf, int32_t order, bool decomp) { // NOTE: mix types tags are not supported size_t sz = 0; if (pBlock->tag.nType == TSDB_DATA_TYPE_BINARY || pBlock->tag.nType == TSDB_DATA_TYPE_NCHAR) { - char* tp = realloc(pBlock->tag.pz, pBlock->tag.nLen + 1); + char* tp = taosMemoryRealloc(pBlock->tag.pz, pBlock->tag.nLen + 1); assert(tp != NULL); memset(tp, 0, pBlock->tag.nLen + 1); @@ -812,7 +812,7 @@ int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf) { if (pDestBuf->numOfAlloc < newSize) { pDestBuf->numOfAlloc = newSize; - STSGroupBlockInfoEx* tmp = realloc(pDestBuf->pData, sizeof(STSGroupBlockInfoEx) * newSize); + STSGroupBlockInfoEx* tmp = taosMemoryRealloc(pDestBuf->pData, sizeof(STSGroupBlockInfoEx) * newSize); if (tmp == NULL) { return -1; } @@ -1028,13 +1028,13 @@ static STSBuf* allocResForTSBuf(STSBuf* pTSBuf) { const int32_t INITIAL_GROUPINFO_SIZE = 4; pTSBuf->numOfAlloc = INITIAL_GROUPINFO_SIZE; - pTSBuf->pData = calloc(pTSBuf->numOfAlloc, sizeof(STSGroupBlockInfoEx)); + pTSBuf->pData = taosMemoryCalloc(pTSBuf->numOfAlloc, sizeof(STSGroupBlockInfoEx)); if (pTSBuf->pData == NULL) { tsBufDestroy(pTSBuf); return NULL; } - pTSBuf->tsData.rawBuf = malloc(MEM_BUF_SIZE); + pTSBuf->tsData.rawBuf = taosMemoryMalloc(MEM_BUF_SIZE); if (pTSBuf->tsData.rawBuf == NULL) { tsBufDestroy(pTSBuf); return NULL; @@ -1044,13 +1044,13 @@ static STSBuf* allocResForTSBuf(STSBuf* pTSBuf) { pTSBuf->tsData.threshold = MEM_BUF_SIZE; pTSBuf->tsData.allocSize = MEM_BUF_SIZE; - pTSBuf->assistBuf = malloc(MEM_BUF_SIZE); + pTSBuf->assistBuf = taosMemoryMalloc(MEM_BUF_SIZE); if (pTSBuf->assistBuf == NULL) { tsBufDestroy(pTSBuf); return NULL; } - pTSBuf->block.payload = malloc(MEM_BUF_SIZE); + pTSBuf->block.payload = taosMemoryMalloc(MEM_BUF_SIZE); if (pTSBuf->block.payload == NULL) { tsBufDestroy(pTSBuf); return NULL; @@ -1079,7 +1079,7 @@ void tsBufGetGroupIdList(STSBuf* pTSBuf, int32_t* num, int32_t** id) { return; } - (*id) = malloc(tsBufGetNumOfGroup(pTSBuf) * sizeof(int32_t)); + (*id) = taosMemoryMalloc(tsBufGetNumOfGroup(pTSBuf) * sizeof(int32_t)); for (int32_t i = 0; i < size; ++i) { (*id)[i] = pTSBuf->pData[i].info.id; diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c index c6aa1cb81d..3995db89b6 100644 --- a/source/common/src/tvariant.c +++ b/source/common/src/tvariant.c @@ -199,14 +199,14 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin case TSDB_DATA_TYPE_NCHAR: { // here we get the nchar length from raw binary bits length size_t lenInwchar = len / TSDB_NCHAR_SIZE; - pVar->ucs4 = calloc(1, (lenInwchar + 1) * TSDB_NCHAR_SIZE); + pVar->ucs4 = taosMemoryCalloc(1, (lenInwchar + 1) * TSDB_NCHAR_SIZE); memcpy(pVar->ucs4, pz, lenInwchar * TSDB_NCHAR_SIZE); pVar->nLen = (int32_t)len; break; } case TSDB_DATA_TYPE_BINARY: { // todo refactor, extract a method - pVar->pz = calloc(len + 1, sizeof(char)); + pVar->pz = taosMemoryCalloc(len + 1, sizeof(char)); memcpy(pVar->pz, pz, len); pVar->nLen = (int32_t)len; break; @@ -224,7 +224,7 @@ void taosVariantDestroy(SVariant *pVar) { if (pVar == NULL) return; if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) { - tfree(pVar->pz); + taosMemoryFreeClear(pVar->pz); pVar->nLen = 0; } @@ -233,7 +233,7 @@ void taosVariantDestroy(SVariant *pVar) { size_t num = taosArrayGetSize(pVar->arr); for (size_t i = 0; i < num; i++) { void *p = taosArrayGetP(pVar->arr, i); - free(p); + taosMemoryFree(p); } taosArrayDestroy(pVar->arr); pVar->arr = NULL; @@ -254,7 +254,7 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) { pDst->nType = pSrc->nType; if (pSrc->nType == TSDB_DATA_TYPE_BINARY || pSrc->nType == TSDB_DATA_TYPE_NCHAR) { int32_t len = pSrc->nLen + TSDB_NCHAR_SIZE; - char *p = realloc(pDst->pz, len); + char *p = taosMemoryRealloc(pDst->pz, len); assert(p); memset(p, 0, len); @@ -402,18 +402,18 @@ static int32_t toBinary(SVariant *pVariant, char **pDest, int32_t *pDestSize) { // it is a in-place convert type for SVariant, local buffer is needed if (*pDest == pVariant->pz) { - pBuf = calloc(1, INITIAL_ALLOC_SIZE); + pBuf = taosMemoryCalloc(1, INITIAL_ALLOC_SIZE); } if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { size_t newSize = pVariant->nLen * TSDB_NCHAR_SIZE; if (pBuf != NULL) { if (newSize >= INITIAL_ALLOC_SIZE) { - pBuf = realloc(pBuf, newSize + 1); + pBuf = taosMemoryRealloc(pBuf, newSize + 1); } taosUcs4ToMbs(pVariant->ucs4, (int32_t)newSize, pBuf); - free(pVariant->ucs4); + taosMemoryFree(pVariant->ucs4); pBuf[newSize] = 0; } else { taosUcs4ToMbs(pVariant->ucs4, (int32_t)newSize, *pDest); @@ -460,23 +460,23 @@ static int32_t toNchar(SVariant *pVariant, char **pDest, int32_t *pDestSize) { } if (*pDest == pVariant->pz) { - TdUcs4 *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE); + TdUcs4 *pWStr = taosMemoryCalloc(1, (nLen + 1) * TSDB_NCHAR_SIZE); bool ret = taosMbsToUcs4(pDst, nLen, pWStr, (nLen + 1) * TSDB_NCHAR_SIZE, NULL); if (!ret) { - tfree(pWStr); + taosMemoryFreeClear(pWStr); return -1; } // free the binary buffer in the first place if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - free(pVariant->ucs4); + taosMemoryFree(pVariant->ucs4); } pVariant->ucs4 = pWStr; *pDestSize = taosUcs4len(pVariant->ucs4); // shrink the allocate memory, no need to check here. - char *tmp = realloc(pVariant->ucs4, (*pDestSize + 1) * TSDB_NCHAR_SIZE); + char *tmp = taosMemoryRealloc(pVariant->ucs4, (*pDestSize + 1) * TSDB_NCHAR_SIZE); assert(tmp != NULL); pVariant->ucs4 = (TdUcs4 *)tmp; @@ -526,7 +526,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result if (token.type == TK_NULL) { if (releaseVariantPtr) { - free(pVariant->pz); + taosMemoryFree(pVariant->pz); pVariant->nLen = 0; } @@ -547,7 +547,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result } if (releaseVariantPtr) { - free(pVariant->pz); + taosMemoryFree(pVariant->pz); pVariant->nLen = 0; } @@ -566,7 +566,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result if (token.type == TK_FLOAT) { double v = wcstod(pVariant->ucs4, &endPtr); if (releaseVariantPtr) { - free(pVariant->pz); + taosMemoryFree(pVariant->pz); pVariant->nLen = 0; } @@ -577,7 +577,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result *result = (int64_t)v; } else if (token.type == TK_NULL) { if (releaseVariantPtr) { - free(pVariant->pz); + taosMemoryFree(pVariant->pz); pVariant->nLen = 0; } setNull((char *)result, type, tDataTypes[type].bytes); @@ -585,7 +585,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result } else { int64_t val = wcstoll(pVariant->ucs4, &endPtr, 10); if (releaseVariantPtr) { - free(pVariant->pz); + taosMemoryFree(pVariant->pz); pVariant->nLen = 0; } @@ -971,21 +971,21 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type) { errno = 0; double v = strtod(pVariant->pz, NULL); if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - free(pVariant->pz); + taosMemoryFree(pVariant->pz); return -1; } - free(pVariant->pz); + taosMemoryFree(pVariant->pz); pVariant->d = v; } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { errno = 0; double v = wcstod(pVariant->ucs4, NULL); if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - free(pVariant->pz); + taosMemoryFree(pVariant->pz); return -1; } - free(pVariant->pz); + taosMemoryFree(pVariant->pz); pVariant->d = v; } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { double tmp = (double)pVariant->i; diff --git a/source/common/test/commonTests.cpp b/source/common/test/commonTests.cpp index d5fb61929a..ccd800d3f4 100644 --- a/source/common/test/commonTests.cpp +++ b/source/common/test/commonTests.cpp @@ -99,7 +99,7 @@ TEST(testCase, toInteger_test) { } TEST(testCase, Datablock_test) { - SSDataBlock* b = static_cast(calloc(1, sizeof(SSDataBlock))); + SSDataBlock* b = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); b->info.numOfCols = 2; b->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); @@ -108,8 +108,8 @@ TEST(testCase, Datablock_test) { infoData.info.type = TSDB_DATA_TYPE_INT; infoData.info.colId = 1; - infoData.pData = (char*) calloc(40, infoData.info.bytes); - infoData.nullbitmap = (char*) calloc(1, sizeof(char) * (40/8)); + infoData.pData = (char*) taosMemoryCalloc(40, infoData.info.bytes); + infoData.nullbitmap = (char*) taosMemoryCalloc(1, sizeof(char) * (40/8)); taosArrayPush(b->pDataBlock, &infoData); SColumnInfoData infoData1 = {0}; @@ -117,7 +117,7 @@ TEST(testCase, Datablock_test) { infoData1.info.type = TSDB_DATA_TYPE_BINARY; infoData1.info.colId = 2; - infoData1.varmeta.offset = (int32_t*) calloc(40, sizeof(uint32_t)); + infoData1.varmeta.offset = (int32_t*) taosMemoryCalloc(40, sizeof(uint32_t)); taosArrayPush(b->pDataBlock, &infoData1); char* str = "the value of: %d"; @@ -178,7 +178,7 @@ TEST(testCase, Datablock_test) { #if 0 TEST(testCase, non_var_dataBlock_split_test) { - SSDataBlock* b = static_cast(calloc(1, sizeof(SSDataBlock))); + SSDataBlock* b = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); b->info.numOfCols = 2; b->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); @@ -189,8 +189,8 @@ TEST(testCase, non_var_dataBlock_split_test) { int32_t numOfRows = 1000000; - infoData.pData = (char*) calloc(numOfRows, infoData.info.bytes); - infoData.nullbitmap = (char*) calloc(1, sizeof(char) * (numOfRows/8)); + infoData.pData = (char*) taosMemoryCalloc(numOfRows, infoData.info.bytes); + infoData.nullbitmap = (char*) taosMemoryCalloc(1, sizeof(char) * (numOfRows/8)); taosArrayPush(b->pDataBlock, &infoData); SColumnInfoData infoData1 = {0}; @@ -198,8 +198,8 @@ TEST(testCase, non_var_dataBlock_split_test) { infoData1.info.type = TSDB_DATA_TYPE_TINYINT; infoData1.info.colId = 2; - infoData1.pData = (char*) calloc(numOfRows, infoData.info.bytes); - infoData1.nullbitmap = (char*) calloc(1, sizeof(char) * (numOfRows/8)); + infoData1.pData = (char*) taosMemoryCalloc(numOfRows, infoData.info.bytes); + infoData1.nullbitmap = (char*) taosMemoryCalloc(1, sizeof(char) * (numOfRows/8)); taosArrayPush(b->pDataBlock, &infoData1); for(int32_t i = 0; i < numOfRows; ++i) { @@ -233,7 +233,7 @@ TEST(testCase, non_var_dataBlock_split_test) { #endif TEST(testCase, var_dataBlock_split_test) { - SSDataBlock* b = static_cast(calloc(1, sizeof(SSDataBlock))); + SSDataBlock* b = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); b->info.numOfCols = 2; b->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); @@ -244,8 +244,8 @@ TEST(testCase, var_dataBlock_split_test) { infoData.info.type = TSDB_DATA_TYPE_INT; infoData.info.colId = 1; - infoData.pData = (char*) calloc(numOfRows, infoData.info.bytes); - infoData.nullbitmap = (char*) calloc(1, sizeof(char) * (numOfRows/8)); + infoData.pData = (char*) taosMemoryCalloc(numOfRows, infoData.info.bytes); + infoData.nullbitmap = (char*) taosMemoryCalloc(1, sizeof(char) * (numOfRows/8)); taosArrayPush(b->pDataBlock, &infoData); SColumnInfoData infoData1 = {0}; @@ -253,7 +253,7 @@ TEST(testCase, var_dataBlock_split_test) { infoData1.info.type = TSDB_DATA_TYPE_BINARY; infoData1.info.colId = 2; - infoData1.varmeta.offset = (int32_t*) calloc(numOfRows, sizeof(uint32_t)); + infoData1.varmeta.offset = (int32_t*) taosMemoryCalloc(numOfRows, sizeof(uint32_t)); taosArrayPush(b->pDataBlock, &infoData1); char buf[41] = {0}; diff --git a/source/dnode/bnode/src/bnode.c b/source/dnode/bnode/src/bnode.c index 4236e85a7f..b9c41ebf43 100644 --- a/source/dnode/bnode/src/bnode.c +++ b/source/dnode/bnode/src/bnode.c @@ -16,12 +16,12 @@ #include "bndInt.h" SBnode *bndOpen(const char *path, const SBnodeOpt *pOption) { - SBnode *pBnode = calloc(1, sizeof(SBnode)); + SBnode *pBnode = taosMemoryCalloc(1, sizeof(SBnode)); pBnode->msgCb = pOption->msgCb; return pBnode; } -void bndClose(SBnode *pBnode) { free(pBnode); } +void bndClose(SBnode *pBnode) { taosMemoryFree(pBnode); } int32_t bndGetLoad(SBnode *pBnode, SBnodeLoad *pLoad) { return 0; } diff --git a/source/dnode/mgmt/bnode/src/bmInt.c b/source/dnode/mgmt/bnode/src/bmInt.c index 34c6dbeb57..e2506ab383 100644 --- a/source/dnode/mgmt/bnode/src/bmInt.c +++ b/source/dnode/mgmt/bnode/src/bmInt.c @@ -73,7 +73,7 @@ int32_t bmDrop(SMgmtWrapper *pWrapper) { bmCloseImp(pMgmt); taosRemoveDir(pMgmt->path); pWrapper->pMgmt = NULL; - free(pMgmt); + taosMemoryFree(pMgmt); dInfo("bnode-mgmt is dropped"); return 0; } @@ -85,13 +85,13 @@ static void bmClose(SMgmtWrapper *pWrapper) { dInfo("bnode-mgmt start to cleanup"); bmCloseImp(pMgmt); pWrapper->pMgmt = NULL; - free(pMgmt); + taosMemoryFree(pMgmt); dInfo("bnode-mgmt is cleaned up"); } int32_t bmOpen(SMgmtWrapper *pWrapper) { dInfo("bnode-mgmt start to init"); - SBnodeMgmt *pMgmt = calloc(1, sizeof(SBnodeMgmt)); + SBnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SBnodeMgmt)); if (pMgmt == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index 6d07ca1898..3c29f80c94 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -139,7 +139,7 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRsp, int32_t dTrace("msg:%p, get from parent queue", pRsp); pRsp->pCont = pCont; dndSendRpcRsp(pWrapper, pRsp); - free(pRsp); + taosMemoryFree(pRsp); } static int32_t dndRunInMultiProcess(SDnode *pDnode) { @@ -174,8 +174,8 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, .parentQueueSize = 1024 * 1024 * 2, // size will be a configuration item .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, - .parentdMallocHeadFp = (ProcMallocFp)malloc, - .parentFreeHeadFp = (ProcFreeFp)free, + .parentdMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, + .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, .testFlag = 0, diff --git a/source/dnode/mgmt/container/src/dndFile.c b/source/dnode/mgmt/container/src/dndFile.c index a5f8fb7169..f860bf8e2d 100644 --- a/source/dnode/mgmt/container/src/dndFile.c +++ b/source/dnode/mgmt/container/src/dndFile.c @@ -20,7 +20,7 @@ int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR; int32_t len = 0; int32_t maxLen = 1024; - char *content = calloc(1, maxLen + 1); + char *content = taosMemoryCalloc(1, maxLen + 1); cJSON *root = NULL; char file[PATH_MAX]; TdFilePtr pFile = NULL; @@ -57,7 +57,7 @@ int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed); _OVER: - if (content != NULL) free(content); + if (content != NULL) taosMemoryFree(content); if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); @@ -78,7 +78,7 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { int32_t len = 0; int32_t maxLen = 1024; - char *content = calloc(1, maxLen + 1); + char *content = taosMemoryCalloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed); @@ -87,7 +87,7 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { taosWriteFile(pFile, content, len); taosFsyncFile(pFile); taosCloseFile(&pFile); - free(content); + taosMemoryFree(content); char realfile[PATH_MAX]; snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); diff --git a/source/dnode/mgmt/container/src/dndObj.c b/source/dnode/mgmt/container/src/dndObj.c index d618f4e503..ff414b5f5e 100644 --- a/source/dnode/mgmt/container/src/dndObj.c +++ b/source/dnode/mgmt/container/src/dndObj.c @@ -39,19 +39,19 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { static void dndClearMemory(SDnode *pDnode) { for (ENodeType n = 0; n < NODE_MAX; ++n) { SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; - tfree(pMgmt->path); + taosMemoryFreeClear(pMgmt->path); } if (pDnode->pLockFile != NULL) { taosUnLockFile(pDnode->pLockFile); taosCloseFile(&pDnode->pLockFile); pDnode->pLockFile = NULL; } - tfree(pDnode->localEp); - tfree(pDnode->localFqdn); - tfree(pDnode->firstEp); - tfree(pDnode->secondEp); - tfree(pDnode->dataDir); - free(pDnode); + taosMemoryFreeClear(pDnode->localEp); + taosMemoryFreeClear(pDnode->localFqdn); + taosMemoryFreeClear(pDnode->firstEp); + taosMemoryFreeClear(pDnode->secondEp); + taosMemoryFreeClear(pDnode->dataDir); + taosMemoryFree(pDnode); dDebug("dnode object memory is cleared, data:%p", pDnode); } @@ -61,7 +61,7 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { char path[PATH_MAX] = {0}; SDnode *pDnode = NULL; - pDnode = calloc(1, sizeof(SDnode)); + pDnode = taosMemoryCalloc(1, sizeof(SDnode)); if (pDnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; diff --git a/source/dnode/mgmt/dnode/src/dmFile.c b/source/dnode/mgmt/dnode/src/dmFile.c index 9acfc2960f..d44b1222a3 100644 --- a/source/dnode/mgmt/dnode/src/dmFile.c +++ b/source/dnode/mgmt/dnode/src/dmFile.c @@ -24,7 +24,7 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR; int32_t len = 0; int32_t maxLen = 256 * 1024; - char *content = calloc(1, maxLen + 1); + char *content = taosMemoryCalloc(1, maxLen + 1); cJSON *root = NULL; char file[PATH_MAX]; TdFilePtr pFile = NULL; @@ -134,7 +134,7 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { dmPrintDnodes(pMgmt); PRASE_DNODE_OVER: - if (content != NULL) free(content); + if (content != NULL) taosMemoryFree(content); if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); @@ -171,7 +171,7 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { int32_t len = 0; int32_t maxLen = 256 * 1024; - char *content = calloc(1, maxLen + 1); + char *content = taosMemoryCalloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->dnodeId); @@ -197,7 +197,7 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { taosWriteFile(pFile, content, len); taosFsyncFile(pFile); taosCloseFile(&pFile); - free(content); + taosMemoryFree(content); char realfile[PATH_MAX]; snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP); diff --git a/source/dnode/mgmt/dnode/src/dmInt.c b/source/dnode/mgmt/dnode/src/dmInt.c index 8aa87cb7bc..53049f7e78 100644 --- a/source/dnode/mgmt/dnode/src/dmInt.c +++ b/source/dnode/mgmt/dnode/src/dmInt.c @@ -80,7 +80,7 @@ static int32_t dmStart(SMgmtWrapper *pWrapper) { int32_t dmInit(SMgmtWrapper *pWrapper) { SDnode *pDnode = pWrapper->pDnode; - SDnodeMgmt *pMgmt = calloc(1, sizeof(SDnodeMgmt)); + SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt)); dInfo("dnode-mgmt start to init"); pDnode->dnodeId = 0; @@ -138,7 +138,7 @@ void dmCleanup(SMgmtWrapper *pWrapper) { taosWUnLockLatch(&pMgmt->latch); - free(pMgmt); + taosMemoryFree(pMgmt); pWrapper->pMgmt = NULL; dInfo("dnode-mgmt is cleaned up"); } diff --git a/source/dnode/mgmt/mnode/src/mmFile.c b/source/dnode/mgmt/mnode/src/mmFile.c index 757b397473..e5cc0ce087 100644 --- a/source/dnode/mgmt/mnode/src/mmFile.c +++ b/source/dnode/mgmt/mnode/src/mmFile.c @@ -20,7 +20,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed) { int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR; int32_t len = 0; int32_t maxLen = 4096; - char *content = calloc(1, maxLen + 1); + char *content = taosMemoryCalloc(1, maxLen + 1); cJSON *root = NULL; char file[PATH_MAX]; TdFilePtr pFile = NULL; @@ -97,7 +97,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed) { dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed); PRASE_MNODE_OVER: - if (content != NULL) free(content); + if (content != NULL) taosMemoryFree(content); if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); @@ -118,7 +118,7 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { int32_t len = 0; int32_t maxLen = 4096; - char *content = calloc(1, maxLen + 1); + char *content = taosMemoryCalloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", deployed); @@ -139,7 +139,7 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { taosWriteFile(pFile, content, len); taosFsyncFile(pFile); taosCloseFile(&pFile); - free(content); + taosMemoryFree(content); char realfile[PATH_MAX]; snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP); diff --git a/source/dnode/mgmt/mnode/src/mmInt.c b/source/dnode/mgmt/mnode/src/mmInt.c index 1f60007be1..cefa36ef10 100644 --- a/source/dnode/mgmt/mnode/src/mmInt.c +++ b/source/dnode/mgmt/mnode/src/mmInt.c @@ -177,7 +177,7 @@ int32_t mmDrop(SMgmtWrapper *pWrapper) { mmCloseImp(pMgmt); taosRemoveDir(pMgmt->path); pWrapper->pMgmt = NULL; - free(pMgmt); + taosMemoryFree(pMgmt); dInfo("mnode-mgmt is dropped"); return 0; } @@ -189,7 +189,7 @@ static void mmClose(SMgmtWrapper *pWrapper) { dInfo("mnode-mgmt start to cleanup"); mmCloseImp(pMgmt); pWrapper->pMgmt = NULL; - free(pMgmt); + taosMemoryFree(pMgmt); dInfo("mnode-mgmt is cleaned up"); } @@ -200,7 +200,7 @@ int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) { return -1; } - SMnodeMgmt *pMgmt = calloc(1, sizeof(SMnodeMgmt)); + SMnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SMnodeMgmt)); if (pMgmt == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; diff --git a/source/dnode/mgmt/qnode/src/qmInt.c b/source/dnode/mgmt/qnode/src/qmInt.c index 2bbfbd83f5..c8cb7258c3 100644 --- a/source/dnode/mgmt/qnode/src/qmInt.c +++ b/source/dnode/mgmt/qnode/src/qmInt.c @@ -76,7 +76,7 @@ int32_t qmDrop(SMgmtWrapper *pWrapper) { qmCloseImp(pMgmt); taosRemoveDir(pMgmt->path); pWrapper->pMgmt = NULL; - free(pMgmt); + taosMemoryFree(pMgmt); dInfo("qnode-mgmt is dropped"); return 0; } @@ -88,13 +88,13 @@ static void qmClose(SMgmtWrapper *pWrapper) { dInfo("qnode-mgmt start to cleanup"); qmCloseImp(pMgmt); pWrapper->pMgmt = NULL; - free(pMgmt); + taosMemoryFree(pMgmt); dInfo("qnode-mgmt is cleaned up"); } int32_t qmOpen(SMgmtWrapper *pWrapper) { dInfo("qnode-mgmt start to init"); - SQnodeMgmt *pMgmt = calloc(1, sizeof(SQnodeMgmt)); + SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt)); if (pMgmt == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; diff --git a/source/dnode/mgmt/snode/src/smInt.c b/source/dnode/mgmt/snode/src/smInt.c index b4d6576e57..351f7d656e 100644 --- a/source/dnode/mgmt/snode/src/smInt.c +++ b/source/dnode/mgmt/snode/src/smInt.c @@ -73,7 +73,7 @@ int32_t smDrop(SMgmtWrapper *pWrapper) { smCloseImp(pMgmt); taosRemoveDir(pMgmt->path); pWrapper->pMgmt = NULL; - free(pMgmt); + taosMemoryFree(pMgmt); dInfo("snode-mgmt is dropped"); return 0; } @@ -85,13 +85,13 @@ static void smClose(SMgmtWrapper *pWrapper) { dInfo("snode-mgmt start to cleanup"); smCloseImp(pMgmt); pWrapper->pMgmt = NULL; - free(pMgmt); + taosMemoryFree(pMgmt); dInfo("snode-mgmt is cleaned up"); } int32_t smOpen(SMgmtWrapper *pWrapper) { dInfo("snode-mgmt start to init"); - SSnodeMgmt *pMgmt = calloc(1, sizeof(SSnodeMgmt)); + SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt)); if (pMgmt == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; diff --git a/source/dnode/mgmt/snode/src/smWorker.c b/source/dnode/mgmt/snode/src/smWorker.c index 4881764906..5913713ff3 100644 --- a/source/dnode/mgmt/snode/src/smWorker.c +++ b/source/dnode/mgmt/snode/src/smWorker.c @@ -51,7 +51,7 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { } for (int32_t i = 0; i < SND_UNIQUE_THREAD_NUM; i++) { - SMultiWorker *pUniqueWorker = malloc(sizeof(SMultiWorker)); + SMultiWorker *pUniqueWorker = taosMemoryMalloc(sizeof(SMultiWorker)); if (pUniqueWorker == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; diff --git a/source/dnode/mgmt/test/sut/inc/sut.h b/source/dnode/mgmt/test/sut/inc/sut.h index 304a370bcd..f7e2831160 100644 --- a/source/dnode/mgmt/test/sut/inc/sut.h +++ b/source/dnode/mgmt/test/sut/inc/sut.h @@ -98,7 +98,7 @@ class Testbase { #define CheckBinaryByte(b, len) \ { \ - char* bytes = (char*)calloc(1, len); \ + char* bytes = (char*)taosMemoryCalloc(1, len); \ for (int32_t i = 0; i < len - 1; ++i) { \ bytes[i] = b; \ } \ diff --git a/source/dnode/mgmt/test/sut/src/client.cpp b/source/dnode/mgmt/test/sut/src/client.cpp index f22bc9d276..a1165d5bc9 100644 --- a/source/dnode/mgmt/test/sut/src/client.cpp +++ b/source/dnode/mgmt/test/sut/src/client.cpp @@ -25,9 +25,9 @@ static void processClientRsp(void* parent, SRpcMsg* pRsp, SEpSet* pEpSet) { void TestClient::SetRpcRsp(SRpcMsg* rsp) { if (this->pRsp) { - free(this->pRsp); + taosMemoryFree(this->pRsp); } - this->pRsp = (SRpcMsg*)calloc(1, sizeof(SRpcMsg)); + this->pRsp = (SRpcMsg*)taosMemoryCalloc(1, sizeof(SRpcMsg)); this->pRsp->msgType = rsp->msgType; this->pRsp->code = rsp->code; this->pRsp->pCont = rsp->pCont; diff --git a/source/dnode/mgmt/vnode/src/vmFile.c b/source/dnode/mgmt/vnode/src/vmFile.c index 0fe868dfa4..d4f906b482 100644 --- a/source/dnode/mgmt/vnode/src/vmFile.c +++ b/source/dnode/mgmt/vnode/src/vmFile.c @@ -21,7 +21,7 @@ SVnodeObj **vmGetVnodesFromHash(SVnodesMgmt *pMgmt, int32_t *numOfVnodes) { int32_t num = 0; int32_t size = taosHashGetSize(pMgmt->hash); - SVnodeObj **pVnodes = calloc(size, sizeof(SVnodeObj *)); + SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *)); void *pIter = taosHashIterate(pMgmt->hash, NULL); while (pIter) { @@ -48,7 +48,7 @@ int32_t vmGetVnodesFromFile(SVnodesMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *n int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR; int32_t len = 0; int32_t maxLen = 30000; - char *content = calloc(1, maxLen + 1); + char *content = taosMemoryCalloc(1, maxLen + 1); cJSON *root = NULL; FILE *fp = NULL; char file[PATH_MAX]; @@ -85,7 +85,7 @@ int32_t vmGetVnodesFromFile(SVnodesMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *n int32_t vnodesNum = cJSON_GetArraySize(vnodes); if (vnodesNum > 0) { - pCfgs = calloc(vnodesNum, sizeof(SWrapperCfg)); + pCfgs = taosMemoryCalloc(vnodesNum, sizeof(SWrapperCfg)); if (pCfgs == NULL) { dError("failed to read %s since out of memory", file); goto PRASE_VNODE_OVER; @@ -140,7 +140,7 @@ int32_t vmGetVnodesFromFile(SVnodesMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *n dInfo("succcessed to read file %s", file); PRASE_VNODE_OVER: - if (content != NULL) free(content); + if (content != NULL) taosMemoryFree(content); if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); @@ -166,7 +166,7 @@ int32_t vmWriteVnodesToFile(SVnodesMgmt *pMgmt) { int32_t len = 0; int32_t maxLen = 65536; - char *content = calloc(1, maxLen + 1); + char *content = taosMemoryCalloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, " \"vnodes\": [\n"); @@ -190,7 +190,7 @@ int32_t vmWriteVnodesToFile(SVnodesMgmt *pMgmt) { taosWriteFile(pFile, content, len); taosFsyncFile(pFile); taosCloseFile(&pFile); - free(content); + taosMemoryFree(content); terrno = 0; for (int32_t i = 0; i < numOfVnodes; ++i) { @@ -199,7 +199,7 @@ int32_t vmWriteVnodesToFile(SVnodesMgmt *pMgmt) { } if (pVnodes != NULL) { - free(pVnodes); + taosMemoryFree(pVnodes); } dDebug("successed to write %s", realfile); diff --git a/source/dnode/mgmt/vnode/src/vmInt.c b/source/dnode/mgmt/vnode/src/vmInt.c index 71f8f23b24..464e789e46 100644 --- a/source/dnode/mgmt/vnode/src/vmInt.c +++ b/source/dnode/mgmt/vnode/src/vmInt.c @@ -46,7 +46,7 @@ void vmReleaseVnode(SVnodesMgmt *pMgmt, SVnodeObj *pVnode) { } int32_t vmOpenVnode(SVnodesMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) { - SVnodeObj *pVnode = calloc(1, sizeof(SVnodeObj)); + SVnodeObj *pVnode = taosMemoryCalloc(1, sizeof(SVnodeObj)); if (pVnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -107,9 +107,9 @@ void vmCloseVnode(SVnodesMgmt *pMgmt, SVnodeObj *pVnode) { vnodeDestroy(pVnode->path); } - free(pVnode->path); - free(pVnode->db); - free(pVnode); + taosMemoryFree(pVnode->path); + taosMemoryFree(pVnode->db); + taosMemoryFree(pVnode); } static void *vmOpenVnodeFunc(void *param) { @@ -183,11 +183,11 @@ static int32_t vmOpenVnodes(SVnodesMgmt *pMgmt) { #endif int32_t vnodesPerThread = numOfVnodes / threadNum + 1; - SVnodeThread *threads = calloc(threadNum, sizeof(SVnodeThread)); + SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread)); for (int32_t t = 0; t < threadNum; ++t) { threads[t].threadIndex = t; threads[t].pMgmt = pMgmt; - threads[t].pCfgs = calloc(vnodesPerThread, sizeof(SWrapperCfg)); + threads[t].pCfgs = taosMemoryCalloc(vnodesPerThread, sizeof(SWrapperCfg)); } for (int32_t v = 0; v < numOfVnodes; ++v) { @@ -217,10 +217,10 @@ static int32_t vmOpenVnodes(SVnodesMgmt *pMgmt) { if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) { taosThreadJoin(pThread->thread, NULL); } - free(pThread->pCfgs); + taosMemoryFree(pThread->pCfgs); } - free(threads); - free(pCfgs); + taosMemoryFree(threads); + taosMemoryFree(pCfgs); if (pMgmt->state.openVnodes != pMgmt->state.totalVnodes) { dError("there are total vnodes:%d, opened:%d", pMgmt->state.totalVnodes, pMgmt->state.openVnodes); @@ -242,7 +242,7 @@ static void vmCloseVnodes(SVnodesMgmt *pMgmt) { } if (pVnodes != NULL) { - free(pVnodes); + taosMemoryFree(pVnodes); } if (pMgmt->hash != NULL) { @@ -262,14 +262,14 @@ static void vmCleanup(SMgmtWrapper *pWrapper) { vmStopWorker(pMgmt); vnodeCleanup(); // walCleanUp(); - free(pMgmt); + taosMemoryFree(pMgmt); pWrapper->pMgmt = NULL; dInfo("vnode-mgmt is cleaned up"); } static int32_t vmInit(SMgmtWrapper *pWrapper) { SDnode *pDnode = pWrapper->pDnode; - SVnodesMgmt *pMgmt = calloc(1, sizeof(SVnodesMgmt)); + SVnodesMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SVnodesMgmt)); int32_t code = -1; dInfo("vnode-mgmt start to init"); diff --git a/source/dnode/mgmt/vnode/src/vmWorker.c b/source/dnode/mgmt/vnode/src/vmWorker.c index d736626a71..4667ebc50d 100644 --- a/source/dnode/mgmt/vnode/src/vmWorker.c +++ b/source/dnode/mgmt/vnode/src/vmWorker.c @@ -117,7 +117,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO if (pRsp != NULL) { pRsp->ahandle = pRpc->ahandle; dndSendRsp(pVnode->pWrapper, pRsp); - free(pRsp); + taosMemoryFree(pRsp); } else { if (code != 0 && terrno != 0) code = terrno; vmSendRsp(pVnode->pWrapper, pMsg, code); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 0585ae5556..eb7ac5b353 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -442,7 +442,7 @@ static FORCE_INLINE void* tDecodeSMqConsumerEp(void** buf, SMqConsumerEp* pConsu static FORCE_INLINE void tDeleteSMqConsumerEp(SMqConsumerEp* pConsumerEp) { if (pConsumerEp) { - tfree(pConsumerEp->qmsg); + taosMemoryFreeClear(pConsumerEp->qmsg); } } @@ -511,7 +511,7 @@ typedef struct { } SMqSubscribeObj; static FORCE_INLINE SMqSubscribeObj* tNewSubscribeObj() { - SMqSubscribeObj* pSub = calloc(1, sizeof(SMqSubscribeObj)); + SMqSubscribeObj* pSub = taosMemoryCalloc(1, sizeof(SMqSubscribeObj)); if (pSub == NULL) { return NULL; } @@ -538,10 +538,10 @@ static FORCE_INLINE SMqSubscribeObj* tNewSubscribeObj() { return pSub; _err: - tfree(pSub->consumers); - tfree(pSub->lostConsumers); - tfree(pSub->unassignedVg); - tfree(pSub); + taosMemoryFreeClear(pSub->consumers); + taosMemoryFreeClear(pSub->lostConsumers); + taosMemoryFreeClear(pSub->unassignedVg); + taosMemoryFreeClear(pSub); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index a6e6d57345..68c8c6d127 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -158,7 +158,7 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { ACCT_DECODE_OVER: if (terrno != 0) { mError("acct:%s, failed to decode from raw:%p since %s", pAcct->acct, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index d9a0df555c..c4868d9802 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -126,7 +126,7 @@ static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) { BNODE_DECODE_OVER: if (terrno != 0) { mError("bnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -191,7 +191,7 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S createReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &createReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -206,7 +206,7 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } @@ -218,7 +218,7 @@ static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S dropReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -233,7 +233,7 @@ static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } @@ -341,7 +341,7 @@ static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBn dropReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -356,7 +356,7 @@ static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBn action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index ce47080645..dde7e1fe8f 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -116,7 +116,7 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) { CLUSTER_DECODE_OVER: if (terrno != 0) { mError("cluster:%" PRId64 ", failed to decode from raw:%p since %s", pCluster->id, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index d86665b832..8eceea3d06 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -54,7 +54,7 @@ int32_t mndInitConsumer(SMnode *pMnode) { void mndCleanupConsumer(SMnode *pMnode) {} SMqConsumerObj *mndCreateConsumer(int64_t consumerId, const char *cgroup) { - SMqConsumerObj *pConsumer = calloc(1, sizeof(SMqConsumerObj)); + SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj)); if (pConsumer == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -79,7 +79,7 @@ SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) { SSdbRaw *pRaw = sdbAllocRaw(SDB_CONSUMER, MND_CONSUMER_VER_NUMBER, size); if (pRaw == NULL) goto CM_ENCODE_OVER; - buf = malloc(tlen); + buf = taosMemoryMalloc(tlen); if (buf == NULL) goto CM_ENCODE_OVER; void *abuf = buf; @@ -94,7 +94,7 @@ SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) { terrno = TSDB_CODE_SUCCESS; CM_ENCODE_OVER: - tfree(buf); + taosMemoryFreeClear(buf); if (terrno != 0) { mError("consumer:%" PRId64 ", failed to encode to raw:%p since %s", pConsumer->consumerId, pRaw, terrstr()); sdbFreeRaw(pRaw); @@ -126,7 +126,7 @@ SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) { int32_t dataPos = 0; int32_t len; SDB_GET_INT32(pRaw, dataPos, &len, CM_DECODE_OVER); - buf = malloc(len); + buf = taosMemoryMalloc(len); if (buf == NULL) goto CM_DECODE_OVER; SDB_GET_BINARY(pRaw, dataPos, buf, len, CM_DECODE_OVER); SDB_GET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE, CM_DECODE_OVER); @@ -138,10 +138,10 @@ SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_SUCCESS; CM_DECODE_OVER: - tfree(buf); + taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { mError("consumer:%" PRId64 ", failed to decode from raw:%p since %s", pConsumer->consumerId, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 183e142624..c556cfc71e 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -193,7 +193,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { DB_DECODE_OVER: if (terrno != 0) { mError("db:%s, failed to decode from raw:%p since %s", pDb->name, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -370,7 +370,7 @@ static int32_t mndSetCreateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.msgType = TDMT_DND_CREATE_VNODE; action.acceptableCode = TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } } @@ -401,7 +401,7 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.msgType = TDMT_DND_DROP_VNODE; action.acceptableCode = TSDB_CODE_DND_VNODE_NOT_DEPLOYED; if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } } @@ -483,7 +483,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate code = 0; CREATE_DB_OVER: - free(pVgroups); + taosMemoryFree(pVgroups); mndTransDrop(pTrans); return code; } @@ -622,7 +622,7 @@ static int32_t mndBuildUpdateVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj action.contLen = contLen; action.msgType = TDMT_DND_ALTER_VNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } } @@ -802,7 +802,7 @@ static int32_t mndBuildDropVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj * action.msgType = TDMT_DND_DROP_VNODE; action.acceptableCode = TSDB_CODE_DND_VNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } } @@ -845,7 +845,7 @@ static int32_t mndBuildDropDbRsp(SDbObj *pDb, int32_t *pRspLen, void **ppRsp, bo if (useRpcMalloc) { pRsp = rpcMallocCont(rspLen); } else { - pRsp = malloc(rspLen); + pRsp = taosMemoryMalloc(rspLen); } if (pRsp == NULL) { @@ -1156,7 +1156,7 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, } int32_t rspLen = tSerializeSUseDbBatchRsp(NULL, 0, &batchUseRsp); - void *pRsp = malloc(rspLen); + void *pRsp = taosMemoryMalloc(rspLen); if (pRsp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; tFreeSUseDbBatchRsp(&batchUseRsp); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 3e47f3a9e8..5541412460 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -164,7 +164,7 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) { DNODE_DECODE_OVER: if (terrno != 0) { mError("dnode:%d, failed to decode from raw:%p since %s", pDnode->id, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index b43d887dd7..be4198f0d6 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -127,8 +127,8 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pFunc->commentSize, FUNC_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pFunc->codeSize, FUNC_DECODE_OVER) - pFunc->pComment = calloc(1, pFunc->commentSize); - pFunc->pCode = calloc(1, pFunc->codeSize); + pFunc->pComment = taosMemoryCalloc(1, pFunc->commentSize); + pFunc->pCode = taosMemoryCalloc(1, pFunc->codeSize); if (pFunc->pComment == NULL || pFunc->pCode == NULL) { goto FUNC_DECODE_OVER; } @@ -142,7 +142,7 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { FUNC_DECODE_OVER: if (terrno != 0) { mError("func:%s, failed to decode from raw:%p since %s", pFunc->name, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -157,8 +157,8 @@ static int32_t mndFuncActionInsert(SSdb *pSdb, SFuncObj *pFunc) { static int32_t mndFuncActionDelete(SSdb *pSdb, SFuncObj *pFunc) { mTrace("func:%s, perform delete action, row:%p", pFunc->name, pFunc); - tfree(pFunc->pCode); - tfree(pFunc->pComment); + taosMemoryFreeClear(pFunc->pCode); + taosMemoryFreeClear(pFunc->pComment); return 0; } @@ -196,8 +196,8 @@ static int32_t mndCreateFunc(SMnode *pMnode, SNodeMsg *pReq, SCreateFuncReq *pCr func.signature = pCreate->signature; func.commentSize = pCreate->commentSize; func.codeSize = pCreate->codeSize; - func.pComment = malloc(func.commentSize); - func.pCode = malloc(func.codeSize); + func.pComment = taosMemoryMalloc(func.commentSize); + func.pCode = taosMemoryMalloc(func.codeSize); if (func.pCode == NULL || func.pCode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto CREATE_FUNC_OVER; @@ -228,8 +228,8 @@ static int32_t mndCreateFunc(SMnode *pMnode, SNodeMsg *pReq, SCreateFuncReq *pCr code = 0; CREATE_FUNC_OVER: - free(func.pCode); - free(func.pComment); + taosMemoryFree(func.pCode); + taosMemoryFree(func.pComment); mndTransDrop(pTrans); return code; } diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index 964c4ab424..5f369e7088 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -152,7 +152,7 @@ static const SInfosTableMeta infosMeta[] = {{TSDB_INS_TABLE_DNODES, dnodesSchema //connection/application/ int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, SSchema **pDst) { - SSchema *schema = calloc(colNum, sizeof(SSchema)); + SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema)); if (NULL == schema) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -210,7 +210,7 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char * *pRsp = *meta; - pRsp->pSchemas = calloc(meta->numOfColumns, sizeof(SSchema)); + pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema)); if (pRsp->pSchemas == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; pRsp->pSchemas = NULL; @@ -241,7 +241,7 @@ void mndCleanupInfos(SMnode *pMnode) { while (pIter) { STableMetaRsp *meta = (STableMetaRsp *)pIter; - tfree(meta->pSchemas); + taosMemoryFreeClear(meta->pSchemas); pIter = taosHashIterate(pMnode->infosMeta, pIter); } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 703f36bb33..c408fea636 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -180,7 +180,7 @@ static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) { MNODE_DECODE_OVER: if (terrno != 0) { mError("mnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -313,7 +313,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno createReq.dnodeId = pMObj->id; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); tSerializeSDCreateMnodeReq(pReq, contLen, &createReq); action.epSet = mndGetDnodeEpset(pMObj->pDnode); @@ -323,7 +323,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pMObj); return -1; @@ -338,7 +338,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno createReq.dnodeId = pObj->id; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); tSerializeSDCreateMnodeReq(pReq, contLen, &createReq); action.epSet = mndGetDnodeEpset(pDnode); @@ -347,7 +347,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno action.msgType = TDMT_DND_CREATE_MNODE; action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } } @@ -483,7 +483,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode alterReq.dnodeId = pMObj->id; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq); action.epSet = mndGetDnodeEpset(pMObj->pDnode); @@ -493,7 +493,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pMObj); return -1; @@ -510,7 +510,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode SDDropMnodeReq dropReq = {0}; dropReq.dnodeId = pObj->id; int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &dropReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); tSerializeSMCreateDropMnodeReq(pReq, contLen, &dropReq); action.epSet = mndGetDnodeEpset(pDnode); @@ -519,7 +519,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode action.msgType = TDMT_DND_DROP_MNODE; action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } } diff --git a/source/dnode/mnode/impl/src/mndOffset.c b/source/dnode/mnode/impl/src/mndOffset.c index 38157cf220..22dad48772 100644 --- a/source/dnode/mnode/impl/src/mndOffset.c +++ b/source/dnode/mnode/impl/src/mndOffset.c @@ -59,7 +59,7 @@ SSdbRaw *mndOffsetActionEncode(SMqOffsetObj *pOffset) { SSdbRaw *pRaw = sdbAllocRaw(SDB_OFFSET, MND_OFFSET_VER_NUMBER, size); if (pRaw == NULL) goto OFFSET_ENCODE_OVER; - buf = malloc(tlen); + buf = taosMemoryMalloc(tlen); if (buf == NULL) goto OFFSET_ENCODE_OVER; void *abuf = buf; @@ -74,7 +74,7 @@ SSdbRaw *mndOffsetActionEncode(SMqOffsetObj *pOffset) { terrno = TSDB_CODE_SUCCESS; OFFSET_ENCODE_OVER: - tfree(buf); + taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { mError("offset:%s, failed to encode to raw:%p since %s", pOffset->key, pRaw, terrstr()); sdbFreeRaw(pRaw); @@ -107,7 +107,7 @@ SSdbRow *mndOffsetActionDecode(SSdbRaw *pRaw) { int32_t dataPos = 0; int32_t tlen; SDB_GET_INT32(pRaw, dataPos, &tlen, OFFSET_DECODE_OVER); - buf = malloc(tlen + 1); + buf = taosMemoryMalloc(tlen + 1); if (buf == NULL) goto OFFSET_DECODE_OVER; SDB_GET_BINARY(pRaw, dataPos, buf, tlen, OFFSET_DECODE_OVER); SDB_GET_RESERVE(pRaw, dataPos, MND_OFFSET_RESERVE_SIZE, OFFSET_DECODE_OVER); @@ -119,10 +119,10 @@ SSdbRow *mndOffsetActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_SUCCESS; OFFSET_DECODE_OVER: - tfree(buf); + taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { mError("offset:%s, failed to decode from raw:%p since %s", pOffset->key, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 7ca1984457..bf378a4d43 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -130,7 +130,7 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, } static void mndFreeConn(SConnObj *pConn) { - tfree(pConn->pQueries); + taosMemoryFreeClear(pConn->pQueries); mTrace("conn:%d, is destroyed, data:%p", pConn->id, pConn); } @@ -260,7 +260,7 @@ static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatReq *pReq) { if (numOfQueries > 0) { if (pConn->pQueries == NULL) { - pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_SAVE_SIZE); + pConn->pQueries = taosMemoryCalloc(sizeof(SQueryDesc), QUERY_SAVE_SIZE); } pConn->numOfQueries = TMIN(QUERY_SAVE_SIZE, numOfQueries); @@ -276,7 +276,7 @@ static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatReq *pReq) { static SClientHbRsp *mndMqHbBuildRsp(SMnode *pMnode, SClientHbReq *pReq) { #if 0 - SClientHbRsp* pRsp = malloc(sizeof(SClientHbRsp)); + SClientHbRsp* pRsp = taosMemoryMalloc(sizeof(SClientHbRsp)); if (pRsp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -292,7 +292,7 @@ static SClientHbRsp *mndMqHbBuildRsp(SMnode *pMnode, SClientHbReq *pReq) { SHashObj* pObj = pReq->info; SKv* pKv = taosHashGet(pObj, "mq-tmp", strlen("mq-tmp") + 1); if (pKv == NULL) { - free(pRsp); + taosMemoryFree(pRsp); return NULL; } SMqHbMsg mqHb; @@ -325,7 +325,7 @@ static SClientHbRsp *mndMqHbBuildRsp(SMnode *pMnode, SClientHbReq *pReq) { taosArrayPush(batchRsp.batchRsps, &innerBatchRsp); } int32_t tlen = taosEncodeSMqHbBatchRsp(NULL, &batchRsp); - void* buf = malloc(tlen); + void* buf = taosMemoryMalloc(tlen); if (buf == NULL) { //TODO return NULL; @@ -402,7 +402,7 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq) { SClientHbRsp *pRsp = mndMqHbBuildRsp(pMnode, pHbReq); if (pRsp != NULL) { taosArrayPush(batchRsp.rsps, pRsp); - free(pRsp); + taosMemoryFree(pRsp); } } } @@ -418,7 +418,7 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq) { int32_t kvNum = (rsp->info) ? taosArrayGetSize(rsp->info) : 0; for (int32_t n = 0; n < kvNum; ++n) { SKv *kv = taosArrayGet(rsp->info, n); - tfree(kv->value); + taosMemoryFreeClear(kv->value); } taosArrayDestroy(rsp->info); } diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 3c66160c91..4b19a26bc4 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -128,7 +128,7 @@ static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) { QNODE_DECODE_OVER: if (terrno != 0) { mError("qnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -193,7 +193,7 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S createReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &createReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -208,7 +208,7 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } @@ -220,7 +220,7 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S dropReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -235,7 +235,7 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } @@ -343,7 +343,7 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn dropReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -358,7 +358,7 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } @@ -474,7 +474,7 @@ static int32_t mndProcessQnodeListReq(SNodeMsg *pReq) { } int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp); - void *pRsp = malloc(rspLen); + void *pRsp = taosMemoryMalloc(rspLen); if (pRsp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto QNODE_LIST_OVER; diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 4595eeadc9..a59aa3c7e5 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -41,7 +41,7 @@ int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet int32_t size = encoder.pos; int32_t tlen = sizeof(SMsgHead) + size; tCoderClear(&encoder); - void* buf = malloc(tlen); + void* buf = taosMemoryMalloc(tlen); if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -58,7 +58,7 @@ int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet action.contLen = tlen; action.msgType = type; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(buf); + taosMemoryFree(buf); return -1; } return 0; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index eb12347e64..a830ee7104 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -146,7 +146,7 @@ static int32_t mndProcessShowReq(SNodeMsg *pReq) { } showRsp.showId = pShow->id; - showRsp.tableMeta.pSchemas = calloc(TSDB_MAX_COLUMNS, sizeof(SSchema)); + showRsp.tableMeta.pSchemas = taosMemoryCalloc(TSDB_MAX_COLUMNS, sizeof(SSchema)); if (showRsp.tableMeta.pSchemas == NULL) { mndReleaseShowObj(pShow, true); terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 4e3ab8eae4..146975aa38 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -160,25 +160,25 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pSma->astLen, _OVER) if (pSma->exprLen > 0) { - pSma->expr = calloc(pSma->exprLen, 1); + pSma->expr = taosMemoryCalloc(pSma->exprLen, 1); if (pSma->expr == NULL) goto _OVER; SDB_GET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER) } if (pSma->tagsFilterLen > 0) { - pSma->tagsFilter = calloc(pSma->tagsFilterLen, 1); + pSma->tagsFilter = taosMemoryCalloc(pSma->tagsFilterLen, 1); if (pSma->tagsFilter == NULL) goto _OVER; SDB_GET_BINARY(pRaw, dataPos, pSma->tagsFilter, pSma->tagsFilterLen, _OVER) } if (pSma->sqlLen > 0) { - pSma->sql = calloc(pSma->sqlLen, 1); + pSma->sql = taosMemoryCalloc(pSma->sqlLen, 1); if (pSma->sql == NULL) goto _OVER; SDB_GET_BINARY(pRaw, dataPos, pSma->sql, pSma->sqlLen, _OVER) } if (pSma->astLen > 0) { - pSma->ast = calloc(pSma->astLen, 1); + pSma->ast = taosMemoryCalloc(pSma->astLen, 1); if (pSma->ast == NULL) goto _OVER; SDB_GET_BINARY(pRaw, dataPos, pSma->ast, pSma->astLen, _OVER) } @@ -189,9 +189,9 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) { _OVER: if (terrno != 0) { mError("sma:%s, failed to decode from raw:%p since %s", pSma->name, pRaw, terrstr()); - tfree(pSma->expr); - tfree(pSma->tagsFilter); - tfree(pRow); + taosMemoryFreeClear(pSma->expr); + taosMemoryFreeClear(pSma->tagsFilter); + taosMemoryFreeClear(pRow); return NULL; } @@ -206,8 +206,8 @@ static int32_t mndSmaActionInsert(SSdb *pSdb, SSmaObj *pSma) { static int32_t mndSmaActionDelete(SSdb *pSdb, SSmaObj *pSma) { mTrace("sma:%s, perform delete action, row:%p", pSma->name, pSma); - tfree(pSma->tagsFilter); - tfree(pSma->expr); + taosMemoryFreeClear(pSma->tagsFilter); + taosMemoryFreeClear(pSma->expr); return 0; } @@ -261,7 +261,7 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm req.tSma.tagsFilter = pSma->tagsFilter; int32_t contLen = tSerializeSVCreateTSmaReq(NULL, &req) + sizeof(SMsgHead); - SMsgHead *pHead = malloc(contLen); + SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -287,7 +287,7 @@ static void *mndBuildVDropSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSma, tstrncpy(req.indexName, (char *)tNameGetTableName(&name), TSDB_INDEX_NAME_LEN); int32_t contLen = tSerializeSVDropTSmaReq(NULL, &req) + sizeof(SMsgHead); - SMsgHead *pHead = malloc(contLen); + SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -349,7 +349,7 @@ static int32_t mndSetCreateSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.contLen = contLen; action.msgType = TDMT_VND_CREATE_SMA; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); return -1; @@ -382,25 +382,25 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre smaObj.astLen = pCreate->astLen; if (smaObj.exprLen > 0) { - smaObj.expr = malloc(smaObj.exprLen); + smaObj.expr = taosMemoryMalloc(smaObj.exprLen); if (smaObj.expr == NULL) goto _OVER; memcpy(smaObj.expr, pCreate->expr, smaObj.exprLen); } if (smaObj.tagsFilterLen > 0) { - smaObj.tagsFilter = malloc(smaObj.tagsFilterLen); + smaObj.tagsFilter = taosMemoryMalloc(smaObj.tagsFilterLen); if (smaObj.tagsFilter == NULL) goto _OVER; memcpy(smaObj.tagsFilter, pCreate->tagsFilter, smaObj.tagsFilterLen); } if (smaObj.sqlLen > 0) { - smaObj.sql = malloc(smaObj.sqlLen); + smaObj.sql = taosMemoryMalloc(smaObj.sqlLen); if (smaObj.sql == NULL) goto _OVER; memcpy(smaObj.sql, pCreate->sql, smaObj.sqlLen); } if (smaObj.astLen > 0) { - smaObj.ast = malloc(smaObj.astLen); + smaObj.ast = taosMemoryMalloc(smaObj.astLen); if (smaObj.ast == NULL) goto _OVER; memcpy(smaObj.ast, pCreate->ast, smaObj.astLen); } @@ -596,7 +596,7 @@ static int32_t mndSetDropSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * action.msgType = TDMT_VND_DROP_SMA; action.acceptableCode = TSDB_CODE_VND_SMA_NOT_EXIST; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); return -1; diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index f01b143fbc..5e0d9fae9a 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -135,7 +135,7 @@ static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) { SNODE_DECODE_OVER: if (terrno != 0) { mError("snode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -200,7 +200,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S createReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &createReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -215,7 +215,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } @@ -227,7 +227,7 @@ static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S dropReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -242,7 +242,7 @@ static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } @@ -352,7 +352,7 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn dropReq.dnodeId = pDnode->id; int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq); - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -367,7 +367,7 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); return -1; } diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index c167a44e9d..acf45a31d9 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -175,9 +175,9 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pStb->numOfSmas, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->commentLen, STB_DECODE_OVER) - pStb->pColumns = calloc(pStb->numOfColumns, sizeof(SSchema)); - pStb->pTags = calloc(pStb->numOfTags, sizeof(SSchema)); - pStb->pSmas = calloc(pStb->numOfSmas, sizeof(SSchema)); + pStb->pColumns = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchema)); + pStb->pTags = taosMemoryCalloc(pStb->numOfTags, sizeof(SSchema)); + pStb->pSmas = taosMemoryCalloc(pStb->numOfSmas, sizeof(SSchema)); if (pStb->pColumns == NULL || pStb->pTags == NULL || pStb->pSmas == NULL) { goto STB_DECODE_OVER; } @@ -207,7 +207,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { } if (pStb->commentLen > 0) { - pStb->comment = calloc(pStb->commentLen, 1); + pStb->comment = taosMemoryCalloc(pStb->commentLen, 1); if (pStb->comment == NULL) goto STB_DECODE_OVER; SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, STB_DECODE_OVER) } @@ -218,10 +218,10 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { STB_DECODE_OVER: if (terrno != 0) { mError("stb:%s, failed to decode from raw:%p since %s", pStb->name, pRaw, terrstr()); - tfree(pStb->pColumns); - tfree(pStb->pTags); - tfree(pStb->comment); - tfree(pRow); + taosMemoryFreeClear(pStb->pColumns); + taosMemoryFreeClear(pStb->pTags); + taosMemoryFreeClear(pStb->comment); + taosMemoryFreeClear(pRow); return NULL; } @@ -236,9 +236,9 @@ static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb) { static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb) { mTrace("stb:%s, perform delete action, row:%p", pStb->name, pStb); - tfree(pStb->pColumns); - tfree(pStb->pTags); - tfree(pStb->comment); + taosMemoryFreeClear(pStb->pColumns); + taosMemoryFreeClear(pStb->pTags); + taosMemoryFreeClear(pStb->comment); return 0; } @@ -248,9 +248,9 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { taosWLockLatch(&pOld->lock); if (pOld->numOfColumns < pNew->numOfColumns) { - void *pColumns = malloc(pNew->numOfColumns * sizeof(SSchema)); + void *pColumns = taosMemoryMalloc(pNew->numOfColumns * sizeof(SSchema)); if (pColumns != NULL) { - free(pOld->pColumns); + taosMemoryFree(pOld->pColumns); pOld->pColumns = pColumns; } else { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -260,9 +260,9 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { } if (pOld->numOfTags < pNew->numOfTags) { - void *pTags = malloc(pNew->numOfTags * sizeof(SSchema)); + void *pTags = taosMemoryMalloc(pNew->numOfTags * sizeof(SSchema)); if (pTags != NULL) { - free(pOld->pTags); + taosMemoryFree(pOld->pTags); pOld->pTags = pTags; } else { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -272,9 +272,9 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { } if (pOld->numOfSmas < pNew->numOfSmas) { - void *pSmas = malloc(pNew->numOfSmas * sizeof(SSchema)); + void *pSmas = taosMemoryMalloc(pNew->numOfSmas * sizeof(SSchema)); if (pSmas != NULL) { - free(pOld->pSmas); + taosMemoryFree(pOld->pSmas); pOld->pSmas = pSmas; } else { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -284,9 +284,9 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { } if (pOld->commentLen < pNew->commentLen) { - void *comment = malloc(pNew->commentLen); + void *comment = taosMemoryMalloc(pNew->commentLen); if (comment != NULL) { - free(pOld->comment); + taosMemoryFree(pOld->comment); pOld->comment = comment; } else { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -353,7 +353,7 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt req.stbCfg.pTagSchema = pStb->pTags; int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead); - SMsgHead *pHead = malloc(contLen); + SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -380,7 +380,7 @@ static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, req.suid = pStb->uid; int32_t contLen = tSerializeSVDropTbReq(NULL, &req) + sizeof(SMsgHead); - SMsgHead *pHead = malloc(contLen); + SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -508,7 +508,7 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.contLen = contLen; action.msgType = TDMT_VND_CREATE_STB; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); return -1; @@ -547,7 +547,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.contLen = contLen; action.msgType = TDMT_VND_DROP_STB; if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); return -1; @@ -584,7 +584,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre stbObj.numOfSmas = pCreate->numOfSmas; stbObj.commentLen = pCreate->commentLen; if (stbObj.commentLen > 0) { - stbObj.comment = calloc(stbObj.commentLen, 1); + stbObj.comment = taosMemoryCalloc(stbObj.commentLen, 1); if (stbObj.comment == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -592,9 +592,9 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre memcpy(stbObj.comment, pCreate->comment, stbObj.commentLen); } - stbObj.pColumns = malloc(stbObj.numOfColumns * sizeof(SSchema)); - stbObj.pTags = malloc(stbObj.numOfTags * sizeof(SSchema)); - stbObj.pSmas = malloc(stbObj.numOfSmas * sizeof(SSchema)); + stbObj.pColumns = taosMemoryMalloc(stbObj.numOfColumns * sizeof(SSchema)); + stbObj.pTags = taosMemoryMalloc(stbObj.numOfTags * sizeof(SSchema)); + stbObj.pSmas = taosMemoryMalloc(stbObj.numOfSmas * sizeof(SSchema)); if (stbObj.pColumns == NULL || stbObj.pTags == NULL || stbObj.pSmas == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -777,8 +777,8 @@ static int32_t mndFindSuperTableColumnIndex(const SStbObj *pStb, const char *col } static int32_t mndAllocStbSchemas(const SStbObj *pOld, SStbObj *pNew) { - pNew->pTags = calloc(pNew->numOfTags, sizeof(SSchema)); - pNew->pColumns = calloc(pNew->numOfColumns, sizeof(SSchema)); + pNew->pTags = taosMemoryCalloc(pNew->numOfTags, sizeof(SSchema)); + pNew->pColumns = taosMemoryCalloc(pNew->numOfColumns, sizeof(SSchema)); if (pNew->pTags == NULL || pNew->pColumns == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -1071,7 +1071,7 @@ static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.contLen = contLen; action.msgType = TDMT_VND_ALTER_STB; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); return -1; @@ -1140,8 +1140,8 @@ static int32_t mndAlterStb(SMnode *pMnode, SNodeMsg *pReq, const SMAltertbReq *p ALTER_STB_OVER: mndTransDrop(pTrans); - tfree(stbObj.pTags); - tfree(stbObj.pColumns); + taosMemoryFreeClear(stbObj.pTags); + taosMemoryFreeClear(stbObj.pColumns); return code; } @@ -1251,7 +1251,7 @@ static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * action.msgType = TDMT_VND_DROP_STB; action.acceptableCode = TSDB_CODE_VND_TB_NOT_EXIST; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pReq); + taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); return -1; @@ -1348,7 +1348,7 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa taosRLockLatch(&pStb->lock); int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; - pRsp->pSchemas = calloc(totalCols, sizeof(SSchema)); + pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema)); if (pRsp->pSchemas == NULL) { taosRUnLockLatch(&pStb->lock); terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -1498,7 +1498,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableMetaVersion *pStbVersions, int return -1; } - void *pRsp = malloc(rspLen); + void *pRsp = taosMemoryMalloc(rspLen); if (pRsp == NULL) { tFreeSTableMetaBatchRsp(&batchMetaRsp); terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index e3d77ced0d..dd62bc0364 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -84,7 +84,7 @@ SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) { SSdbRaw *pRaw = sdbAllocRaw(SDB_STREAM, MND_STREAM_VER_NUMBER, size); if (pRaw == NULL) goto STREAM_ENCODE_OVER; - buf = malloc(tlen); + buf = taosMemoryMalloc(tlen); if (buf == NULL) goto STREAM_ENCODE_OVER; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, tlen, TD_ENCODER); @@ -102,7 +102,7 @@ SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) { terrno = TSDB_CODE_SUCCESS; STREAM_ENCODE_OVER: - tfree(buf); + taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { mError("stream:%s, failed to encode to raw:%p since %s", pStream->name, pRaw, terrstr()); sdbFreeRaw(pRaw); @@ -135,7 +135,7 @@ SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) { int32_t tlen; int32_t dataPos = 0; SDB_GET_INT32(pRaw, dataPos, &tlen, STREAM_DECODE_OVER); - buf = malloc(tlen + 1); + buf = taosMemoryMalloc(tlen + 1); if (buf == NULL) goto STREAM_DECODE_OVER; SDB_GET_BINARY(pRaw, dataPos, buf, tlen, STREAM_DECODE_OVER); @@ -148,10 +148,10 @@ SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_SUCCESS; STREAM_DECODE_OVER: - tfree(buf); + taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { mError("stream:%s, failed to decode from raw:%p since %s", pStream->name, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index a4909dfe37..08a88a19ec 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -94,7 +94,7 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj if (mndSchedInitSubEp(pMnode, pTopic, pSub) < 0) { tDeleteSMqSubscribeObj(pSub); - free(pSub); + taosMemoryFree(pSub); return NULL; } @@ -102,7 +102,7 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj if (mndInitUnassignedVg(pMnode, pTopic, pSub) < 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; tDeleteSMqSubscribeObj(pSub); - free(pSub); + taosMemoryFree(pSub); return NULL; } #endif @@ -118,7 +118,7 @@ static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsume }; int32_t tlen = tEncodeSMqMVRebReq(NULL, &req); - void *buf = malloc(sizeof(SMsgHead) + tlen); + void *buf = taosMemoryMalloc(sizeof(SMsgHead) + tlen); if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -157,7 +157,7 @@ static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqC mndReleaseVgroup(pMnode, pVgObj); if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(buf); + taosMemoryFree(buf); return -1; } @@ -169,7 +169,7 @@ static int32_t mndBuildCancelConnReq(void **pBuf, int32_t *pLen, const SMqConsum req.consumerId = pConsumerEp->consumerId; int32_t tlen = tEncodeSMqSetCVgReq(NULL, &req); - void *buf = malloc(sizeof(SMsgHead) + tlen); + void *buf = taosMemoryMalloc(sizeof(SMsgHead) + tlen); if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -203,7 +203,7 @@ static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMq mndReleaseVgroup(pMnode, pVgObj); if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(buf); + taosMemoryFree(buf); return -1; } @@ -229,7 +229,7 @@ static int32_t mndProcessResetOffsetReq(SNodeMsg *pMsg) { SMqOffset *pOffset = &req.offsets[i]; SMqVgOffsets *pVgOffset = taosHashGet(pHash, &pOffset->vgId, sizeof(int32_t)); if (pVgOffset == NULL) { - pVgOffset = malloc(sizeof(SMqVgOffsets)); + pVgOffset = taosMemoryMalloc(sizeof(SMqVgOffsets)); if (pVgOffset == NULL) { return -1; } @@ -407,7 +407,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { int32_t removeSz = taosArrayGetSize(pConsumer->recentRemovedTopics); for (int32_t i = 0; i < removeSz; i++) { char *topicName = taosArrayGet(pConsumer->recentRemovedTopics, i); - free(topicName); + taosMemoryFree(topicName); } taosArrayClear(pConsumer->recentRemovedTopics); } @@ -441,7 +441,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { if (pIter == NULL) break; SMqRebSubscribe *pRebSub = (SMqRebSubscribe *)pIter; SMqSubscribeObj *pSub = mndAcquireSubscribeByKey(pMnode, pRebSub->key); - tfree(pRebSub->key); + taosMemoryFreeClear(pRebSub->key); mInfo("mq rebalance subscription: %s", pSub->key); @@ -762,8 +762,8 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { } mndReleaseTopic(pMnode, pTopic); mndTransDrop(pTrans); - tfree(topic); - tfree(cgroup); + taosMemoryFreeClear(topic); + taosMemoryFreeClear(cgroup); } // rebalance condition2 : imbalance assignment } @@ -836,7 +836,7 @@ static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqT strcpy(req.cgroup, cgroup); strcpy(req.topicName, pTopic->name); int32_t tlen = tEncodeSMqSetCVgReq(NULL, &req); - void *buf = malloc(sizeof(SMsgHead) + tlen); + void *buf = taosMemoryMalloc(sizeof(SMsgHead) + tlen); if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -860,7 +860,7 @@ static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqT mndReleaseVgroup(pMnode, pVgObj); if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(buf); + taosMemoryFree(buf); return -1; } return 0; @@ -877,7 +877,7 @@ static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) { SSdbRaw *pRaw = sdbAllocRaw(SDB_SUBSCRIBE, MND_SUBSCRIBE_VER_NUMBER, size); if (pRaw == NULL) goto SUB_ENCODE_OVER; - buf = malloc(tlen); + buf = taosMemoryMalloc(tlen); if (buf == NULL) goto SUB_ENCODE_OVER; void *abuf = buf; @@ -892,7 +892,7 @@ static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) { terrno = TSDB_CODE_SUCCESS; SUB_ENCODE_OVER: - tfree(buf); + taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { mError("subscribe:%s, failed to encode to raw:%p since %s", pSub->key, pRaw, terrstr()); sdbFreeRaw(pRaw); @@ -925,7 +925,7 @@ static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) { int32_t dataPos = 0; int32_t tlen; SDB_GET_INT32(pRaw, dataPos, &tlen, SUB_DECODE_OVER); - buf = malloc(tlen + 1); + buf = taosMemoryMalloc(tlen + 1); if (buf == NULL) goto SUB_DECODE_OVER; SDB_GET_BINARY(pRaw, dataPos, buf, tlen, SUB_DECODE_OVER); SDB_GET_RESERVE(pRaw, dataPos, MND_SUBSCRIBE_RESERVE_SIZE, SUB_DECODE_OVER); @@ -937,10 +937,10 @@ static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_SUCCESS; SUB_DECODE_OVER: - tfree(buf); + taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { mError("subscribe:%s, failed to decode from raw:%p since %s", pSub->key, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -1140,7 +1140,7 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) { } } - if (oldSub) taosArrayDestroyEx(oldSub, free); + if (oldSub) taosArrayDestroyEx(oldSub, (void (*)(void*))taosMemoryFree); // persist consumerObj SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pConsumer); diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index 7993d7df9d..d6c1b6c94f 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -88,7 +88,7 @@ static int32_t mndProcessTelemTimer(SNodeMsg* pReq) { char* pCont = mndBuildTelemetryReport(pMnode); if (pCont != NULL) { taosSendHttpReport(TELEMETRY_SERVER, TELEMETRY_PORT, pCont, strlen(pCont), HTTP_FLAT); - free(pCont); + taosMemoryFree(pCont); } taosWUnLockLatch(&pMgmt->lock); return 0; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 95dce5d8f1..625c9eb733 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -129,11 +129,11 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pTopic->version, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER); - pTopic->sql = calloc(pTopic->sqlLen + 1, sizeof(char)); + pTopic->sql = taosMemoryCalloc(pTopic->sqlLen + 1, sizeof(char)); SDB_GET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER); - pTopic->logicalPlan = calloc(len + 1, sizeof(char)); + pTopic->logicalPlan = taosMemoryCalloc(len + 1, sizeof(char)); if (pTopic->logicalPlan == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto TOPIC_DECODE_OVER; @@ -141,9 +141,9 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { SDB_GET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER); - pTopic->physicalPlan = calloc(len + 1, sizeof(char)); + pTopic->physicalPlan = taosMemoryCalloc(len + 1, sizeof(char)); if (pTopic->physicalPlan == NULL) { - free(pTopic->logicalPlan); + taosMemoryFree(pTopic->logicalPlan); terrno = TSDB_CODE_OUT_OF_MEMORY; goto TOPIC_DECODE_OVER; } @@ -156,7 +156,7 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { TOPIC_DECODE_OVER: if (terrno != TSDB_CODE_SUCCESS) { mError("topic:%s, failed to decode from raw:%p since %s", pTopic->name, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -214,7 +214,7 @@ static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) { static SDDropTopicReq *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, SMqTopicObj *pTopic) { int32_t contLen = sizeof(SDDropTopicReq); - SDDropTopicReq *pDrop = calloc(1, contLen); + SDDropTopicReq *pDrop = taosMemoryCalloc(1, contLen); if (pDrop == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -286,7 +286,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg); if (pTrans == NULL) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); - tfree(pPlanStr); + taosMemoryFreeClear(pPlanStr); return -1; } mDebug("trans:%d, used to create topic:%s", pTrans->id, pCreate->name); @@ -294,7 +294,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq SSdbRaw *pRedoRaw = mndTopicActionEncode(&topicObj); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); - tfree(pPlanStr); + taosMemoryFreeClear(pPlanStr); mndTransDrop(pTrans); return -1; } @@ -302,12 +302,12 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - tfree(pPlanStr); + taosMemoryFreeClear(pPlanStr); mndTransDrop(pTrans); return -1; } - tfree(pPlanStr); + taosMemoryFreeClear(pPlanStr); mndTransDrop(pTrans); return 0; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index aa39c740ad..3314211437 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -255,7 +255,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < redoLogNum; ++i) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) - pData = malloc(dataLen); + pData = taosMemoryMalloc(dataLen); if (pData == NULL) goto TRANS_DECODE_OVER; mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); @@ -265,7 +265,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < undoLogNum; ++i) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) - pData = malloc(dataLen); + pData = taosMemoryMalloc(dataLen); if (pData == NULL) goto TRANS_DECODE_OVER; mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); @@ -275,7 +275,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < commitLogNum; ++i) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) - pData = malloc(dataLen); + pData = taosMemoryMalloc(dataLen); if (pData == NULL) goto TRANS_DECODE_OVER; mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); @@ -288,7 +288,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER) - action.pCont = malloc(action.contLen); + action.pCont = taosMemoryMalloc(action.contLen); if (action.pCont == NULL) goto TRANS_DECODE_OVER; SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER); if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto TRANS_DECODE_OVER; @@ -300,7 +300,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER) - action.pCont = malloc(action.contLen); + action.pCont = taosMemoryMalloc(action.contLen); if (action.pCont == NULL) goto TRANS_DECODE_OVER; SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER); if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto TRANS_DECODE_OVER; @@ -315,9 +315,9 @@ TRANS_DECODE_OVER: if (terrno != 0) { mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr()); mndTransDropData(pTrans); - tfree(pRow); - tfree(pData); - tfree(action.pCont); + taosMemoryFreeClear(pRow); + taosMemoryFreeClear(pData); + taosMemoryFreeClear(action.pCont); return NULL; } @@ -428,7 +428,7 @@ static void mndTransDropData(STrans *pTrans) { mndTransDropActions(pTrans->redoActions); mndTransDropActions(pTrans->undoActions); if (pTrans->rpcRsp != NULL) { - free(pTrans->rpcRsp); + taosMemoryFree(pTrans->rpcRsp); pTrans->rpcRsp = NULL; pTrans->rpcRspLen = 0; } @@ -472,7 +472,7 @@ static void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) { } STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnType type, const SRpcMsg *pReq) { - STrans *pTrans = calloc(1, sizeof(STrans)); + STrans *pTrans = taosMemoryCalloc(1, sizeof(STrans)); if (pTrans == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed to create transaction since %s", terrstr()); @@ -517,7 +517,7 @@ static void mndTransDropActions(SArray *pArray) { int32_t size = taosArrayGetSize(pArray); for (int32_t i = 0; i < size; ++i) { STransAction *pAction = taosArrayGet(pArray, i); - tfree(pAction->pCont); + taosMemoryFreeClear(pAction->pCont); } taosArrayDestroy(pArray); @@ -527,7 +527,7 @@ void mndTransDrop(STrans *pTrans) { if (pTrans != NULL) { mndTransDropData(pTrans); mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans); - tfree(pTrans); + taosMemoryFreeClear(pTrans); } } @@ -762,7 +762,7 @@ static void mndTransSendRpcRsp(STrans *pTrans) { if (rpcCont != NULL) { memcpy(rpcCont, pTrans->rpcRsp, pTrans->rpcRspLen); } - free(pTrans->rpcRsp); + taosMemoryFree(pTrans->rpcRsp); mDebug("trans:%d, send rsp, code:0x%04x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage, pTrans->rpcAHandle); diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index b7d32c01d9..ff34c26c4a 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -201,7 +201,7 @@ USER_DECODE_OVER: mError("user:%s, failed to decode from raw:%p since %s", pUser->user, pRaw, terrstr()); taosHashCleanup(pUser->readDbs); taosHashCleanup(pUser->writeDbs); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 0b31f7d06c..d36617822d 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -146,7 +146,7 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) { VG_DECODE_OVER: if (terrno != 0) { mError("vgId:%d, failed to decode from raw:%p since %s", pVgroup->vgId, pRaw, terrstr()); - tfree(pRow); + taosMemoryFreeClear(pRow); return NULL; } @@ -250,7 +250,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg return NULL; } - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -274,7 +274,7 @@ void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgOb return NULL; } - void *pReq = malloc(contLen); + void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -376,7 +376,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { SArray *pArray = NULL; SVgObj *pVgroups = NULL; - pVgroups = calloc(pDb->cfg.numOfVgroups, sizeof(SVgObj)); + pVgroups = taosMemoryCalloc(pDb->cfg.numOfVgroups, sizeof(SVgObj)); if (pVgroups == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto ALLOC_VGROUP_OVER; @@ -430,7 +430,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { mDebug("db:%s, %d vgroups is alloced, replica:%d", pDb->name, pDb->cfg.numOfVgroups, pDb->cfg.replications); ALLOC_VGROUP_OVER: - if (code != 0) free(pVgroups); + if (code != 0) taosMemoryFree(pVgroups); taosArrayDestroy(pArray); return code; } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index c4d389a379..08f0b20d31 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -283,7 +283,7 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { mDebug("start to open mnode in %s", path); - SMnode *pMnode = calloc(1, sizeof(SMnode)); + SMnode *pMnode = taosMemoryCalloc(1, sizeof(SMnode)); if (pMnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed to open mnode since %s", terrstr()); @@ -295,7 +295,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { pMnode->pSteps = taosArrayInit(24, sizeof(SMnodeStep)); if (pMnode->pSteps == NULL) { - free(pMnode); + taosMemoryFree(pMnode); terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed to open mnode since %s", terrstr()); return NULL; @@ -346,8 +346,8 @@ void mndClose(SMnode *pMnode) { if (pMnode != NULL) { mDebug("start to close mnode"); mndCleanupSteps(pMnode, -1); - tfree(pMnode->path); - tfree(pMnode); + taosMemoryFreeClear(pMnode->path); + taosMemoryFreeClear(pMnode); mDebug("mnode is closed"); } } diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 9ddb3594bb..b37ec85387 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -29,7 +29,7 @@ class MndTestTrans : public ::testing::Test { char file[PATH_MAX] = "/tmp/mnode_test_trans/mnode/data/sdb.data"; TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ); int32_t size = 3 * 1024 * 1024; - void* buffer = malloc(size); + void* buffer = taosMemoryMalloc(size); int32_t readLen = taosReadFile(pFile, buffer, size); if (readLen < 0 || readLen == size) { ASSERT(1); @@ -43,7 +43,7 @@ class MndTestTrans : public ::testing::Test { if (writeLen < 0 || writeLen == readLen) { ASSERT(1); } - free(buffer); + taosMemoryFree(buffer); taosFsyncFile(pFile); taosCloseFile(&pFile); taosMsleep(1000); diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 26809ea059..c645dae5b5 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -21,7 +21,7 @@ static int32_t sdbCreateDir(SSdb *pSdb); SSdb *sdbInit(SSdbOpt *pOption) { mDebug("start to init sdb in %s", pOption->path); - SSdb *pSdb = calloc(1, sizeof(SSdb)); + SSdb *pSdb = taosMemoryCalloc(1, sizeof(SSdb)); if (pSdb == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed to init sdb since %s", terrstr()); @@ -67,15 +67,15 @@ void sdbCleanup(SSdb *pSdb) { sdbWriteFile(pSdb); if (pSdb->currDir != NULL) { - tfree(pSdb->currDir); + taosMemoryFreeClear(pSdb->currDir); } if (pSdb->syncDir != NULL) { - tfree(pSdb->syncDir); + taosMemoryFreeClear(pSdb->syncDir); } if (pSdb->tmpDir != NULL) { - tfree(pSdb->tmpDir); + taosMemoryFreeClear(pSdb->tmpDir); } for (ESdbType i = 0; i < SDB_MAX; ++i) { @@ -102,7 +102,7 @@ void sdbCleanup(SSdb *pSdb) { mDebug("sdb table:%d is cleaned up", i); } - free(pSdb); + taosMemoryFree(pSdb); mDebug("sdb is cleaned up"); } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 2849da5c2e..c11025beed 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -137,7 +137,7 @@ int32_t sdbReadFile(SSdb *pSdb) { int32_t readLen = 0; int64_t ret = 0; - SSdbRaw *pRaw = malloc(SDB_MAX_SIZE); + SSdbRaw *pRaw = taosMemoryMalloc(SDB_MAX_SIZE); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed read file since %s", terrstr()); @@ -150,7 +150,7 @@ int32_t sdbReadFile(SSdb *pSdb) { TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - free(pRaw); + taosMemoryFree(pRaw); terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to read file:%s since %s", file, terrstr()); return 0; @@ -159,7 +159,7 @@ int32_t sdbReadFile(SSdb *pSdb) { if (sdbReadFileHead(pSdb, pFile) != 0) { mError("failed to read file:%s head since %s", file, terrstr()); pSdb->curVer = -1; - free(pRaw); + taosMemoryFree(pRaw); taosCloseFile(&pFile); return -1; } diff --git a/source/dnode/mnode/sdb/src/sdbRaw.c b/source/dnode/mnode/sdb/src/sdbRaw.c index e37559808e..c3aaf562be 100644 --- a/source/dnode/mnode/sdb/src/sdbRaw.c +++ b/source/dnode/mnode/sdb/src/sdbRaw.c @@ -17,7 +17,7 @@ #include "sdbInt.h" SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) { - SSdbRaw *pRaw = calloc(1, dataLen + sizeof(SSdbRaw)); + SSdbRaw *pRaw = taosMemoryCalloc(1, dataLen + sizeof(SSdbRaw)); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -33,7 +33,7 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) { void sdbFreeRaw(SSdbRaw *pRaw) { mTrace("raw:%p, is freed", pRaw); - free(pRaw); + taosMemoryFree(pRaw); } int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) { diff --git a/source/dnode/mnode/sdb/src/sdbRow.c b/source/dnode/mnode/sdb/src/sdbRow.c index e51dd48dcd..ac86a72155 100644 --- a/source/dnode/mnode/sdb/src/sdbRow.c +++ b/source/dnode/mnode/sdb/src/sdbRow.c @@ -17,7 +17,7 @@ #include "sdbInt.h" SSdbRow *sdbAllocRow(int32_t objSize) { - SSdbRow *pRow = calloc(1, objSize + sizeof(SSdbRow)); + SSdbRow *pRow = taosMemoryCalloc(1, objSize + sizeof(SSdbRow)); if (pRow == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -46,5 +46,5 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow) { sdbPrintOper(pSdb, pRow, "freeRow"); mTrace("row:%p, is freed", pRow->pObj); - tfree(pRow); + taosMemoryFreeClear(pRow); } diff --git a/source/dnode/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c index bc1a602b52..0d1e890097 100644 --- a/source/dnode/qnode/src/qnode.c +++ b/source/dnode/qnode/src/qnode.c @@ -19,14 +19,14 @@ #include "qworker.h" SQnode *qndOpen(const SQnodeOpt *pOption) { - SQnode *pQnode = calloc(1, sizeof(SQnode)); + SQnode *pQnode = taosMemoryCalloc(1, sizeof(SQnode)); if (NULL == pQnode) { qError("calloc SQnode failed"); return NULL; } if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, NULL, (void **)&pQnode->pQuery, &pOption->msgCb)) { - tfree(pQnode); + taosMemoryFreeClear(pQnode); return NULL; } @@ -37,7 +37,7 @@ SQnode *qndOpen(const SQnodeOpt *pOption) { void qndClose(SQnode *pQnode) { qWorkerDestroy((void **)&pQnode->pQuery); - free(pQnode); + taosMemoryFree(pQnode); } int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; } diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index 5a7d6c9acb..a5937b625f 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -18,14 +18,14 @@ #include "tuuid.h" SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) { - SSnode *pSnode = calloc(1, sizeof(SSnode)); + SSnode *pSnode = taosMemoryCalloc(1, sizeof(SSnode)); if (pSnode == NULL) { return NULL; } pSnode->msgCb = pOption->msgCb; pSnode->pMeta = sndMetaNew(); if (pSnode->pMeta == NULL) { - free(pSnode); + taosMemoryFree(pSnode); return NULL; } return pSnode; @@ -33,19 +33,19 @@ SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) { void sndClose(SSnode *pSnode) { sndMetaDelete(pSnode->pMeta); - free(pSnode); + taosMemoryFree(pSnode); } int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; } SStreamMeta *sndMetaNew() { - SStreamMeta *pMeta = calloc(1, sizeof(SStreamMeta)); + SStreamMeta *pMeta = taosMemoryCalloc(1, sizeof(SStreamMeta)); if (pMeta == NULL) { return NULL; } pMeta->pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); if (pMeta->pHash == NULL) { - free(pMeta); + taosMemoryFree(pMeta); return NULL; } return pMeta; @@ -53,7 +53,7 @@ SStreamMeta *sndMetaNew() { void sndMetaDelete(SStreamMeta *pMeta) { taosHashCleanup(pMeta->pHash); - free(pMeta); + taosMemoryFree(pMeta); } int32_t sndMetaDeployTask(SStreamMeta *pMeta, SStreamTask *pTask) { @@ -72,9 +72,9 @@ int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) { if (pTask == NULL) { return -1; } - free(pTask->exec.qmsg); + taosMemoryFree(pTask->exec.qmsg); // TODO:free executor - free(pTask); + taosMemoryFree(pTask); return taosHashRemove(pMeta->pHash, &taskId, sizeof(int32_t)); } @@ -94,7 +94,7 @@ void sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { // operator exec if (pMsg->msgType == TDMT_SND_TASK_DEPLOY) { void *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - SStreamTask *pTask = malloc(sizeof(SStreamTask)); + SStreamTask *pTask = taosMemoryMalloc(sizeof(SStreamTask)); if (pTask == NULL) { ASSERT(0); return; diff --git a/source/dnode/vnode/src/inc/tsdbMemory.h b/source/dnode/vnode/src/inc/tsdbMemory.h index df4df0053f..69976fc078 100644 --- a/source/dnode/vnode/src/inc/tsdbMemory.h +++ b/source/dnode/vnode/src/inc/tsdbMemory.h @@ -30,7 +30,7 @@ static void taosTMemset(void *ptr, int c); static FORCE_INLINE void *taosTMalloc(size_t size) { if (size <= 0) return NULL; - void *ret = malloc(size + sizeof(size_t)); + void *ret = taosMemoryMalloc(size + sizeof(size_t)); if (ret == NULL) return NULL; *(size_t *)ret = size; @@ -58,7 +58,7 @@ static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) { void * tptr = (void *)((char *)ptr - sizeof(size_t)); size_t tsize = size + sizeof(size_t); - void* tptr1 = realloc(tptr, tsize); + void* tptr1 = taosMemoryRealloc(tptr, tsize); if (tptr1 == NULL) return NULL; tptr = tptr1; @@ -69,7 +69,7 @@ static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) { static FORCE_INLINE void* taosTZfree(void* ptr) { if (ptr) { - free((void*)((char*)ptr - sizeof(size_t))); + taosMemoryFree((void*)((char*)ptr - sizeof(size_t))); } return NULL; } diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index e4bad9e94b..fdcc165207 100644 --- a/source/dnode/vnode/src/meta/metaBDBImpl.c +++ b/source/dnode/vnode/src/meta/metaBDBImpl.c @@ -233,7 +233,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { // save sma info int32_t len = tEncodeTSma(NULL, pSmaCfg); - pBuf = calloc(len, 1); + pBuf = taosMemoryCalloc(len, 1); if (pBuf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -254,7 +254,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { metaDBULock(pMeta->pDB); // release - tfree(pBuf); + taosMemoryFreeClear(pBuf); return 0; } @@ -297,7 +297,7 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { SSchema *pSchema; buf = taosDecodeFixedU32(buf, &pSW->nCols); - pSW->pSchema = (SSchema *)malloc(sizeof(SSchema) * pSW->nCols); + pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols); for (int i = 0; i < pSW->nCols; i++) { pSchema = pSW->pSchema + i; buf = taosDecodeFixedI8(buf, &pSchema->type); @@ -311,7 +311,7 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { static SMetaDB *metaNewDB() { SMetaDB *pDB = NULL; - pDB = (SMetaDB *)calloc(1, sizeof(*pDB)); + pDB = (SMetaDB *)taosMemoryCalloc(1, sizeof(*pDB)); if (pDB == NULL) { return NULL; } @@ -328,7 +328,7 @@ static void metaFreeDB(SMetaDB *pDB) { #if IMPL_WITH_LOCK taosThreadRwlockDestroy(&pDB->rwlock); #endif - free(pDB); + taosMemoryFree(pDB); } } @@ -463,7 +463,7 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT *pSKey DBT *pDbt; if (pTbCfg->type == META_CHILD_TABLE) { - // pDbt = calloc(2, sizeof(DBT)); + // pDbt = taosMemoryCalloc(2, sizeof(DBT)); // // First key is suid // pDbt[0].data = &(pTbCfg->ctbCfg.suid); @@ -545,11 +545,11 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) { } static void metaClearTbCfg(STbCfg *pTbCfg) { - tfree(pTbCfg->name); + taosMemoryFreeClear(pTbCfg->name); if (pTbCfg->type == META_SUPER_TABLE) { tdFreeSchema(pTbCfg->stbCfg.pTagSchema); } else if (pTbCfg->type == META_CHILD_TABLE) { - tfree(pTbCfg->ctbCfg.pTag); + taosMemoryFreeClear(pTbCfg->ctbCfg.pTag); } } @@ -574,7 +574,7 @@ STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { } // Decode - pTbCfg = (STbCfg *)malloc(sizeof(*pTbCfg)); + pTbCfg = (STbCfg *)taosMemoryMalloc(sizeof(*pTbCfg)); if (pTbCfg == NULL) { return NULL; } @@ -606,7 +606,7 @@ STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { // Decode *uid = *(tb_uid_t *)(pkey.data); - pTbCfg = (STbCfg *)malloc(sizeof(*pTbCfg)); + pTbCfg = (STbCfg *)taosMemoryMalloc(sizeof(*pTbCfg)); if (pTbCfg == NULL) { return NULL; } @@ -636,13 +636,13 @@ STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { } // Decode - pCfg = (STSma *)calloc(1, sizeof(STSma)); + pCfg = (STSma *)taosMemoryCalloc(1, sizeof(STSma)); if (pCfg == NULL) { return NULL; } if (tDecodeTSma(value.data, pCfg) == NULL) { - tfree(pCfg); + taosMemoryFreeClear(pCfg); return NULL; } @@ -675,7 +675,7 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo // Decode the schema pBuf = value.data; - pSW = malloc(sizeof(*pSW)); + pSW = taosMemoryMalloc(sizeof(*pSW)); metaDecodeSchema(pBuf, pSW); return pSW; @@ -689,7 +689,7 @@ SMTbCursor *metaOpenTbCursor(SMeta *pMeta) { SMTbCursor *pTbCur = NULL; SMetaDB *pDB = pMeta->pDB; - pTbCur = (SMTbCursor *)calloc(1, sizeof(*pTbCur)); + pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur)); if (pTbCur == NULL) { return NULL; } @@ -722,7 +722,7 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) { if (pTbCur->pCur) { pTbCur->pCur->close(pTbCur->pCur); } - free(pTbCur); + taosMemoryFree(pTbCur); } } @@ -737,8 +737,8 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) { pBuf = value.data; metaDecodeTbInfo(pBuf, &tbCfg); if (tbCfg.type == META_SUPER_TABLE) { - free(tbCfg.name); - free(tbCfg.stbCfg.pTagSchema); + taosMemoryFree(tbCfg.name); + taosMemoryFree(tbCfg.stbCfg.pTagSchema); continue; } else if (tbCfg.type == META_CHILD_TABLE) { kvRowFree(tbCfg.ctbCfg.pTag); @@ -792,7 +792,7 @@ SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { SMetaDB *pDB = pMeta->pDB; int ret; - pCtbCur = (SMCtbCursor *)calloc(1, sizeof(*pCtbCur)); + pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur)); if (pCtbCur == NULL) { return NULL; } @@ -800,7 +800,7 @@ SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { pCtbCur->suid = uid; ret = pDB->pCtbIdx->cursor(pDB->pCtbIdx, NULL, &(pCtbCur->pCur), 0); if (ret != 0) { - free(pCtbCur); + taosMemoryFree(pCtbCur); return NULL; } @@ -813,7 +813,7 @@ void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) { pCtbCur->pCur->close(pCtbCur->pCur); } - free(pCtbCur); + taosMemoryFree(pCtbCur); } } @@ -849,7 +849,7 @@ SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) { SMetaDB *pDB = pMeta->pDB; int ret; - pCur = (SMSmaCursor *)calloc(1, sizeof(*pCur)); + pCur = (SMSmaCursor *)taosMemoryCalloc(1, sizeof(*pCur)); if (pCur == NULL) { return NULL; } @@ -858,7 +858,7 @@ SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) { // TODO: lock? ret = pDB->pCtbIdx->cursor(pDB->pSmaIdx, NULL, &(pCur->pCur), 0); if (ret != 0) { - free(pCur); + taosMemoryFree(pCur); return NULL; } @@ -871,7 +871,7 @@ void metaCloseSmaCurosr(SMSmaCursor *pCur) { pCur->pCur->close(pCur->pCur); } - free(pCur); + taosMemoryFree(pCur); } } @@ -896,14 +896,14 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) { STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { STSmaWrapper *pSW = NULL; - pSW = calloc(1, sizeof(*pSW)); + pSW = taosMemoryCalloc(1, sizeof(*pSW)); if (pSW == NULL) { return NULL; } SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, uid); if (pCur == NULL) { - free(pSW); + taosMemoryFree(pSW); return NULL; } @@ -915,11 +915,11 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { // TODO: lock? if (pCur->pCur->pget(pCur->pCur, &skey, NULL, &pval, DB_NEXT) == 0) { ++pSW->number; - STSma *tptr = (STSma *)realloc(pSW->tSma, pSW->number * sizeof(STSma)); + STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma)); if (tptr == NULL) { metaCloseSmaCurosr(pCur); tdDestroyTSmaWrapper(pSW); - tfree(pSW); + taosMemoryFreeClear(pSW); return NULL; } pSW->tSma = tptr; @@ -927,7 +927,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) { metaCloseSmaCurosr(pCur); tdDestroyTSmaWrapper(pSW); - tfree(pSW); + taosMemoryFreeClear(pSW); return NULL; } continue; diff --git a/source/dnode/vnode/src/meta/metaMain.c b/source/dnode/vnode/src/meta/metaMain.c index ad87b2de9e..690b96bbb0 100644 --- a/source/dnode/vnode/src/meta/metaMain.c +++ b/source/dnode/vnode/src/meta/metaMain.c @@ -69,7 +69,7 @@ static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorF SMeta *pMeta; size_t psize = strlen(path); - pMeta = (SMeta *)calloc(1, sizeof(*pMeta)); + pMeta = (SMeta *)taosMemoryCalloc(1, sizeof(*pMeta)); if (pMeta == NULL) { return NULL; } @@ -88,8 +88,8 @@ static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorF static void metaFree(SMeta *pMeta) { if (pMeta) { - tfree(pMeta->path); - free(pMeta); + taosMemoryFreeClear(pMeta->path); + taosMemoryFree(pMeta); } } diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index 4a65cf277b..f4b450b4a8 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -47,7 +47,7 @@ int metaOpenDB(SMeta *pMeta) { TDB * pCtbIdx; int ret; - pDb = (SMetaDB *)calloc(1, sizeof(*pDb)); + pDb = (SMetaDB *)taosMemoryCalloc(1, sizeof(*pDb)); if (pDb == NULL) { return -1; } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 18074fc5a8..9ce4f53d27 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -26,7 +26,7 @@ void tqCleanUp() { tqPushMgrCleanUp(); } STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STqCfg* tqConfig, SMemAllocatorFactory* allocFac) { - STQ* pTq = malloc(sizeof(STQ)); + STQ* pTq = taosMemoryMalloc(sizeof(STQ)); if (pTq == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return NULL; @@ -44,9 +44,9 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STq } #endif pTq->tqMeta = - tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer, free, 0); + tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer, (FTqDelete)taosMemoryFree, 0); if (pTq->tqMeta == NULL) { - free(pTq); + taosMemoryFree(pTq); #if 0 allocFac->destroy(allocFac, pTq->tqMemRef.pAllocator); #endif @@ -57,7 +57,7 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STq pTq->tqPushMgr = tqPushMgrOpen(); if (pTq->tqPushMgr == NULL) { // free store - free(pTq); + taosMemoryFree(pTq); return NULL; } #endif @@ -69,15 +69,15 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STq void tqClose(STQ* pTq) { if (pTq) { - tfree(pTq->path); - free(pTq); + taosMemoryFreeClear(pTq->path); + taosMemoryFree(pTq); } // TODO } int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version) { if (msgType != TDMT_VND_SUBMIT) return 0; - void* data = malloc(msgLen); + void* data = taosMemoryMalloc(msgLen); if (data == NULL) { return -1; } @@ -96,7 +96,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t versi if (pusher->type == TQ_PUSHER_TYPE__STREAM) { STqStreamPusher* streamPusher = (STqStreamPusher*)pusher; // repack - STqStreamToken* token = malloc(sizeof(STqStreamToken)); + STqStreamToken* token = taosMemoryMalloc(sizeof(STqStreamToken)); if (token == NULL) { taosHashCancelIterate(pTq->tqPushMgr->pHash, pIter); terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -200,9 +200,9 @@ int tqSerializeConsumer(const STqConsumer* pConsumer, STqSerializedHead** ppHead int32_t sz = tEncodeSTqConsumer(NULL, pConsumer); if (sz > (*ppHead)->ssize) { - void* tmpPtr = realloc(*ppHead, sizeof(STqSerializedHead) + sz); + void* tmpPtr = taosMemoryRealloc(*ppHead, sizeof(STqSerializedHead) + sz); if (tmpPtr == NULL) { - free(*ppHead); + taosMemoryFree(*ppHead); terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return -1; } @@ -219,7 +219,7 @@ int tqSerializeConsumer(const STqConsumer* pConsumer, STqSerializedHead** ppHead int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsumer** ppConsumer) { const void* str = pHead->content; - *ppConsumer = calloc(1, sizeof(STqConsumer)); + *ppConsumer = taosMemoryCalloc(1, sizeof(STqConsumer)); if (*ppConsumer == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return -1; @@ -393,7 +393,7 @@ int32_t tqProcessSetConnReq(STQ* pTq, char* msg) { tDecodeSMqSetCVgReq(msg, &req); /*printf("vg %d set to consumer from %ld to %ld\n", req.vgId, req.oldConsumerId, req.newConsumerId);*/ - STqConsumer* pConsumer = calloc(1, sizeof(STqConsumer)); + STqConsumer* pConsumer = taosMemoryCalloc(1, sizeof(STqConsumer)); if (pConsumer == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return -1; @@ -404,10 +404,10 @@ int32_t tqProcessSetConnReq(STQ* pTq, char* msg) { pConsumer->consumerId = req.consumerId; pConsumer->epoch = 0; - STqTopic* pTopic = calloc(1, sizeof(STqTopic)); + STqTopic* pTopic = taosMemoryCalloc(1, sizeof(STqTopic)); if (pTopic == NULL) { taosArrayDestroy(pConsumer->topics); - free(pConsumer); + taosMemoryFree(pConsumer); return -1; } strcpy(pTopic->topicName, req.topicName); @@ -451,7 +451,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) { .reader = pReadHandle, .meta = pTq->pVnodeMeta, }; - pTask->exec.runners = calloc(parallel, sizeof(SStreamRunner)); + pTask->exec.runners = taosMemoryCalloc(parallel, sizeof(SStreamRunner)); if (pTask->exec.runners == NULL) { return -1; } @@ -462,7 +462,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) { } int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { - SStreamTask* pTask = malloc(sizeof(SStreamTask)); + SStreamTask* pTask = taosMemoryMalloc(sizeof(SStreamTask)); if (pTask == NULL) { return -1; } diff --git a/source/dnode/vnode/src/tq/tqMetaStore.c b/source/dnode/vnode/src/tq/tqMetaStore.c index ce00c98ff9..505687755d 100644 --- a/source/dnode/vnode/src/tq/tqMetaStore.c +++ b/source/dnode/vnode/src/tq/tqMetaStore.c @@ -70,7 +70,7 @@ static inline int tqReadLastPage(TdFilePtr pFile, STqIdxPageBuf* pBuf) { STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, FTqDeserialize deserializer, FTqDelete deleter, int32_t tqConfigFlag) { - STqMetaStore* pMeta = calloc(1, sizeof(STqMetaStore)); + STqMetaStore* pMeta = taosMemoryCalloc(1, sizeof(STqMetaStore)); if (pMeta == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return NULL; @@ -79,10 +79,10 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F // concat data file name and index file name size_t pathLen = strlen(path); - pMeta->dirPath = malloc(pathLen + 1); + pMeta->dirPath = taosMemoryMalloc(pathLen + 1); if (pMeta->dirPath == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; - free(pMeta); + taosMemoryFree(pMeta); return NULL; } strcpy(pMeta->dirPath, path); @@ -104,7 +104,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F } pMeta->pIdxFile = pIdxFile; - pMeta->unpersistHead = calloc(1, sizeof(STqMetaList)); + pMeta->unpersistHead = taosMemoryCalloc(1, sizeof(STqMetaList)); if (pMeta->unpersistHead == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return NULL; @@ -129,7 +129,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F // read idx file and load into memory STqIdxPageBuf idxBuf; - STqSerializedHead* serializedObj = malloc(TQ_PAGE_SIZE); + STqSerializedHead* serializedObj = taosMemoryMalloc(TQ_PAGE_SIZE); if (serializedObj == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; } @@ -145,7 +145,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F ASSERT(idxBuf.head.writeOffset == idxRead); // loop read every entry for (int i = 0; i < idxBuf.head.writeOffset - TQ_IDX_PAGE_HEAD_SIZE; i += TQ_IDX_SIZE) { - STqMetaList* pNode = calloc(1, sizeof(STqMetaList)); + STqMetaList* pNode = taosMemoryCalloc(1, sizeof(STqMetaList)); if (pNode == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; // TODO: free memory @@ -154,7 +154,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F taosLSeekFile(pFile, pNode->handle.offset, SEEK_SET); if (allocated < pNode->handle.serializedSize) { - void* ptr = realloc(serializedObj, pNode->handle.serializedSize); + void* ptr = taosMemoryRealloc(serializedObj, pNode->handle.serializedSize); if (ptr == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; // TODO: free memory @@ -225,11 +225,11 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F if (pBucketNode->handle.valueInTxn && pBucketNode->handle.valueInTxn != TQ_DELETE_TOKEN) { pMeta->pDeleter(pBucketNode->handle.valueInTxn); } - free(pBucketNode); + taosMemoryFree(pBucketNode); } } } - free(serializedObj); + taosMemoryFree(serializedObj); return pMeta; } @@ -252,13 +252,13 @@ int32_t tqStoreClose(STqMetaStore* pMeta) { pMeta->pDeleter(pNode->handle.valueInUse); } STqMetaList* next = pNode->next; - free(pNode); + taosMemoryFree(pNode); pNode = next; } } - free(pMeta->dirPath); - free(pMeta->unpersistHead); - free(pMeta); + taosMemoryFree(pMeta->dirPath); + taosMemoryFree(pMeta->unpersistHead); + taosMemoryFree(pMeta); return 0; } @@ -277,14 +277,14 @@ int32_t tqStoreDelete(STqMetaStore* pMeta) { pMeta->pDeleter(pNode->handle.valueInUse); } STqMetaList* next = pNode->next; - free(pNode); + taosMemoryFree(pNode); pNode = next; } } - free(pMeta->unpersistHead); + taosMemoryFree(pMeta->unpersistHead); taosRemoveDir(pMeta->dirPath); - free(pMeta->dirPath); - free(pMeta); + taosMemoryFree(pMeta->dirPath); + taosMemoryFree(pMeta); return 0; } @@ -293,7 +293,7 @@ int32_t tqStorePersist(STqMetaStore* pMeta) { int64_t* bufPtr = (int64_t*)idxBuf.buffer; STqMetaList* pHead = pMeta->unpersistHead; STqMetaList* pNode = pHead->unpersistNext; - STqSerializedHead* pSHead = malloc(sizeof(STqSerializedHead)); + STqSerializedHead* pSHead = taosMemoryMalloc(sizeof(STqSerializedHead)); if (pSHead == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return -1; @@ -383,12 +383,12 @@ int32_t tqStorePersist(STqMetaStore* pMeta) { ASSERT(pBucketNode->next == pNode); pBucketNode->next = pNode->next; } - free(pNode); + taosMemoryFree(pNode); } } // write left bytes - free(pSHead); + taosMemoryFree(pSHead); // TODO: write new version in tfile if ((char*)bufPtr != idxBuf.buffer) { int nBytes = taosWriteFile(pMeta->pIdxFile, &idxBuf, idxBuf.head.writeOffset); @@ -416,7 +416,7 @@ static int32_t tqHandlePutCommitted(STqMetaStore* pMeta, int64_t key, void* valu pNode = pNode->next; } } - STqMetaList* pNewNode = calloc(1, sizeof(STqMetaList)); + STqMetaList* pNewNode = taosMemoryCalloc(1, sizeof(STqMetaList)); if (pNewNode == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return -1; @@ -488,7 +488,7 @@ static inline int32_t tqHandlePutImpl(STqMetaStore* pMeta, int64_t key, void* va pNode = pNode->next; } } - STqMetaList* pNewNode = calloc(1, sizeof(STqMetaList)); + STqMetaList* pNewNode = taosMemoryCalloc(1, sizeof(STqMetaList)); if (pNewNode == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return -1; @@ -504,7 +504,7 @@ static inline int32_t tqHandlePutImpl(STqMetaStore* pMeta, int64_t key, void* va int32_t tqHandleMovePut(STqMetaStore* pMeta, int64_t key, void* value) { return tqHandlePutImpl(pMeta, key, value); } int32_t tqHandleCopyPut(STqMetaStore* pMeta, int64_t key, void* value, size_t vsize) { - void* vmem = malloc(vsize); + void* vmem = taosMemoryMalloc(vsize); if (vmem == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return -1; diff --git a/source/dnode/vnode/src/tq/tqOffset.c b/source/dnode/vnode/src/tq/tqOffset.c index 4115cb7313..20270950cd 100644 --- a/source/dnode/vnode/src/tq/tqOffset.c +++ b/source/dnode/vnode/src/tq/tqOffset.c @@ -31,7 +31,7 @@ struct STqOffsetStore { }; STqOffsetStore* STqOffsetOpen(STqOffsetCfg* pCfg) { - STqOffsetStore* pStore = malloc(sizeof(STqOffsetStore)); + STqOffsetStore* pStore = taosMemoryMalloc(sizeof(STqOffsetStore)); if (pStore == NULL) { return NULL; } diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c index 4186f29e2a..7851c071c3 100644 --- a/source/dnode/vnode/src/tq/tqPush.c +++ b/source/dnode/vnode/src/tq/tqPush.c @@ -32,7 +32,7 @@ void tqPushMgrCleanUp() { } STqPushMgr* tqPushMgrOpen() { - STqPushMgr* mgr = malloc(sizeof(STqPushMgr)); + STqPushMgr* mgr = taosMemoryMalloc(sizeof(STqPushMgr)); if (mgr == NULL) { return NULL; } @@ -42,11 +42,11 @@ STqPushMgr* tqPushMgrOpen() { void tqPushMgrClose(STqPushMgr* pushMgr) { taosHashCleanup(pushMgr->pHash); - free(pushMgr); + taosMemoryFree(pushMgr); } STqClientPusher* tqAddClientPusher(STqPushMgr* pushMgr, SRpcMsg* pMsg, int64_t consumerId, int64_t ttl) { - STqClientPusher* clientPusher = malloc(sizeof(STqClientPusher)); + STqClientPusher* clientPusher = taosMemoryMalloc(sizeof(STqClientPusher)); if (clientPusher == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -57,7 +57,7 @@ STqClientPusher* tqAddClientPusher(STqPushMgr* pushMgr, SRpcMsg* pMsg, int64_t c clientPusher->ttl = ttl; if (taosHashPut(pushMgr->pHash, &consumerId, sizeof(int64_t), &clientPusher, sizeof(void*)) < 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; - free(clientPusher); + taosMemoryFree(clientPusher); // TODO send rsp back return NULL; } @@ -65,7 +65,7 @@ STqClientPusher* tqAddClientPusher(STqPushMgr* pushMgr, SRpcMsg* pMsg, int64_t c } STqStreamPusher* tqAddStreamPusher(STqPushMgr* pushMgr, int64_t streamId, SEpSet* pEpSet) { - STqStreamPusher* streamPusher = malloc(sizeof(STqStreamPusher)); + STqStreamPusher* streamPusher = taosMemoryMalloc(sizeof(STqStreamPusher)); if (streamPusher == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -77,7 +77,7 @@ STqStreamPusher* tqAddStreamPusher(STqPushMgr* pushMgr, int64_t streamId, SEpSet if (taosHashPut(pushMgr->pHash, &streamId, sizeof(int64_t), &streamPusher, sizeof(void*)) < 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; - free(streamPusher); + taosMemoryFree(streamPusher); return NULL; } return streamPusher; diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 690787984c..37e7ed11ae 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -17,7 +17,7 @@ #include "vnode.h" STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) { - STqReadHandle* pReadHandle = malloc(sizeof(STqReadHandle)); + STqReadHandle* pReadHandle = taosMemoryMalloc(sizeof(STqReadHandle)); if (pReadHandle == NULL) { return NULL; } @@ -143,7 +143,7 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { colInfo.info.colId = pColSchema->colId; colInfo.info.type = pColSchema->type; - colInfo.pData = calloc(1, sz); + colInfo.pData = taosMemoryCalloc(1, sz); if (colInfo.pData == NULL) { // TODO free taosArrayDestroy(pArray); @@ -173,7 +173,7 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { colInfo.info.colId = colId; colInfo.info.type = pColSchema->type; - colInfo.pData = calloc(1, sz); + colInfo.pData = taosMemoryCalloc(1, sz); if (colInfo.pData == NULL) { // TODO free taosArrayDestroy(pArray); diff --git a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c index ee279abf47..c8f4cd642a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c @@ -51,7 +51,7 @@ void tsdbCloseDBF(SDBFile *pDBF) { tsdbCloseBDBDb(pDBF->pDB); pDBF->pDB = NULL; } - tfree(pDBF->path); + taosMemoryFreeClear(pDBF->path); } int32_t tsdbOpenBDBEnv(DB_ENV **ppEnv, const char *path) { @@ -159,7 +159,7 @@ void *tsdbGetSmaDataByKey(SDBFile *pDBF, void* key, uint32_t keySize, uint32_t * return NULL; } - result = calloc(1, value1.size); + result = taosMemoryCalloc(1, value1.size); if (result == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 37403f1a11..eca0a9612f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -403,7 +403,7 @@ static int tsdbCreateCommitIters(SCommitH *pCommith) { STbData *pTbData; pCommith->niters = SL_SIZE(pMem->pSlIdx); - pCommith->iters = (SCommitIter *)calloc(pCommith->niters, sizeof(SCommitIter)); + pCommith->iters = (SCommitIter *)taosMemoryCalloc(pCommith->niters, sizeof(SCommitIter)); if (pCommith->iters == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; @@ -424,7 +424,7 @@ static int tsdbCreateCommitIters(SCommitH *pCommith) { pCommitIter->pIter = tSkipListCreateIter(pTbData->pData); tSkipListIterNext(pCommitIter->pIter); - pCommitIter->pTable = (STable *)malloc(sizeof(STable)); + pCommitIter->pTable = (STable *)taosMemoryMalloc(sizeof(STable)); pCommitIter->pTable->uid = pTbData->uid; pCommitIter->pTable->tid = pTbData->uid; pCommitIter->pTable->pSchema = metaGetTbTSchema(pRepo->pMeta, pTbData->uid, 0); @@ -439,10 +439,10 @@ static void tsdbDestroyCommitIters(SCommitH *pCommith) { for (int i = 1; i < pCommith->niters; i++) { tSkipListDestroyIter(pCommith->iters[i].pIter); tdFreeSchema(pCommith->iters[i].pTable->pSchema); - free(pCommith->iters[i].pTable); + taosMemoryFree(pCommith->iters[i].pTable); } - free(pCommith->iters); + taosMemoryFree(pCommith->iters); pCommith->iters = NULL; pCommith->niters = 0; } @@ -985,7 +985,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) { // SKVRecord *pRecord; // void *pBuf = NULL; -// pBuf = malloc((size_t)maxBufSize); +// pBuf = taosMemoryMalloc((size_t)maxBufSize); // if (pBuf == NULL) { // goto _err; // } @@ -1006,7 +1006,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) { // } // if (pRecord->size > maxBufSize) { // maxBufSize = pRecord->size; -// void* tmp = realloc(pBuf, (size_t)maxBufSize); +// void* tmp = taosMemoryRealloc(pBuf, (size_t)maxBufSize); // if (tmp == NULL) { // goto _err; // } @@ -1059,7 +1059,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) { // pfs->metaCacheComp = NULL; // } -// tfree(pBuf); +// taosMemoryFreeClear(pBuf); // ASSERT(mf.info.nDels == 0); // ASSERT(mf.info.tombSize == 0); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index fa867543b0..aa235f88de 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -134,7 +134,7 @@ static void *tsdbDecodeFSStatus(STsdb*pRepo, void *buf, SFSStatus *pStatus) { } static SFSStatus *tsdbNewFSStatus(int maxFSet) { - SFSStatus *pStatus = (SFSStatus *)calloc(1, sizeof(*pStatus)); + SFSStatus *pStatus = (SFSStatus *)taosMemoryCalloc(1, sizeof(*pStatus)); if (pStatus == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; @@ -145,7 +145,7 @@ static SFSStatus *tsdbNewFSStatus(int maxFSet) { pStatus->df = taosArrayInit(maxFSet, sizeof(SDFileSet)); if (pStatus->df == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - free(pStatus); + taosMemoryFree(pStatus); return NULL; } @@ -155,7 +155,7 @@ static SFSStatus *tsdbNewFSStatus(int maxFSet) { static SFSStatus *tsdbFreeFSStatus(SFSStatus *pStatus) { if (pStatus) { pStatus->df = taosArrayDestroy(pStatus->df); - free(pStatus); + taosMemoryFree(pStatus); } return NULL; @@ -197,7 +197,7 @@ STsdbFS *tsdbNewFS(const STsdbCfg *pCfg) { int maxFSet = TSDB_MAX_FSETS(keep, days); STsdbFS *pfs; - pfs = (STsdbFS *)calloc(1, sizeof(*pfs)); + pfs = (STsdbFS *)taosMemoryCalloc(1, sizeof(*pfs)); if (pfs == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; @@ -206,7 +206,7 @@ STsdbFS *tsdbNewFS(const STsdbCfg *pCfg) { int code = taosThreadRwlockInit(&(pfs->lock), NULL); if (code) { terrno = TAOS_SYSTEM_ERROR(code); - free(pfs); + taosMemoryFree(pfs); return NULL; } @@ -242,7 +242,7 @@ void *tsdbFreeFS(STsdbFS *pfs) { pfs->metaCache = NULL; pfs->cstatus = tsdbFreeFSStatus(pfs->cstatus); taosThreadRwlockDestroy(&(pfs->lock)); - free(pfs); + taosMemoryFree(pfs); } return NULL; @@ -853,7 +853,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) { // } // if (recoverMeta) { -// pBuf = malloc((size_t)maxBufSize); +// pBuf = taosMemoryMalloc((size_t)maxBufSize); // if (pBuf == NULL) { // terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; // tsdbCloseMFile(pMFile); @@ -865,7 +865,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) { // if (tsdbSeekMFile(pMFile, pRecord->offset + sizeof(SKVRecord), SEEK_SET) < 0) { // tsdbError("vgId:%d failed to seek file %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile), // tstrerror(terrno)); -// tfree(pBuf); +// taosMemoryFreeClear(pBuf); // tsdbCloseMFile(pMFile); // return -1; // } @@ -874,7 +874,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) { // if (nread < 0) { // tsdbError("vgId:%d failed to read file %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile), // tstrerror(terrno)); -// tfree(pBuf); +// taosMemoryFreeClear(pBuf); // tsdbCloseMFile(pMFile); // return -1; // } @@ -883,7 +883,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) { // tsdbError("vgId:%d failed to read file %s since file corrupted, expected read:%" PRId64 " actual read:%d", // REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile), pRecord->size, nread); // terrno = TSDB_CODE_TDB_FILE_CORRUPTED; -// tfree(pBuf); +// taosMemoryFreeClear(pBuf); // tsdbCloseMFile(pMFile); // return -1; // } @@ -891,7 +891,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) { // if (tsdbRestoreTable(pRepo, pBuf, (int)pRecord->size) < 0) { // tsdbError("vgId:%d failed to restore table, uid %" PRId64 ", since %s" PRIu64, REPO_ID(pRepo), pRecord->uid, // tstrerror(terrno)); -// tfree(pBuf); +// taosMemoryFreeClear(pBuf); // tsdbCloseMFile(pMFile); // return -1; // } @@ -903,7 +903,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) { // } // tsdbCloseMFile(pMFile); -// tfree(pBuf); +// taosMemoryFreeClear(pBuf); // return 0; // } diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 00e97c7b61..271616e9c2 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -85,7 +85,7 @@ void *tsdbDecodeSMFileEx(void *buf, SMFile *pMFile) { strncpy(TSDB_FILE_FULL_NAME(pMFile), aname, TSDB_FILENAME_LEN); TSDB_FILE_SET_CLOSED(pMFile); - tfree(aname); + taosMemoryFreeClear(aname); return buf; } @@ -119,10 +119,10 @@ int tsdbCreateMFile(SMFile *pMFile, bool updateHeader) { // Try to create directory recursively char *s = strdup(TFILE_REL_NAME(&(pMFile->f))); if (tfsMkdirRecurAt(dirname(s), TSDB_FILE_LEVEL(pMFile), TSDB_FILE_ID(pMFile)) < 0) { - tfree(s); + taosMemoryFreeClear(s); return -1; } - tfree(s); + taosMemoryFreeClear(s); pMFile->fd = open(TSDB_FILE_FULL_NAME(pMFile), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0755); if (pMFile->fd < 0) { @@ -352,7 +352,7 @@ static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) { buf = taosDecodeString(buf, &aname); strncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN); TSDB_FILE_SET_CLOSED(pDFile); - tfree(aname); + taosMemoryFreeClear(aname); return buf; } @@ -366,10 +366,10 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T // Try to create directory recursively char *s = strdup(TSDB_FILE_REL_NAME(pDFile)); if (tfsMkdirRecurAt(pRepo->pTfs, taosDirName(s), TSDB_FILE_DID(pDFile)) < 0) { - tfree(s); + taosMemoryFreeClear(s); return -1; } - tfree(s); + taosMemoryFreeClear(s); pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pDFile->pFile == NULL) { @@ -692,7 +692,7 @@ int tsdbParseDFilename(const char *fname, int *vid, int *fid, TSDB_FILE_T *ftype } } - tfree(p); + taosMemoryFreeClear(p); return 0; } diff --git a/source/dnode/vnode/src/tsdb/tsdbMain.c b/source/dnode/vnode/src/tsdb/tsdbMain.c index 131e92cab6..526109f796 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMain.c +++ b/source/dnode/vnode/src/tsdb/tsdbMain.c @@ -68,7 +68,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMeta *pMeta, STfs *pTfs) { STsdb *pTsdb = NULL; - pTsdb = (STsdb *)calloc(1, sizeof(STsdb)); + pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb)); if (pTsdb == NULL) { // TODO: handle error return NULL; @@ -93,8 +93,8 @@ static void tsdbFree(STsdb *pTsdb) { tsdbFreeSmaEnv(pTsdb->pRSmaEnv); tsdbFreeSmaEnv(pTsdb->pTSmaEnv); tsdbFreeFS(pTsdb->fs); - tfree(pTsdb->path); - free(pTsdb); + taosMemoryFreeClear(pTsdb->path); + taosMemoryFree(pTsdb); } } @@ -507,7 +507,7 @@ uint32_t tsdbGetFileInfo(STsdbRepo *repo, char *name, uint32_t *index, uint32_t magic = pFile->info.magic; char *tfname = strdup(fname); sprintf(name, "tsdb/%s/%s", TSDB_DATA_DIR_NAME, basename(tfname)); - tfree(tfname); + taosMemoryFreeClear(tfname); } else { if ((pFGroup->fileId + 1) * TSDB_FILE_TYPE_MAX - 1 < (int)eindex) { SFile *pFile = &pFGroup->files[0]; @@ -516,17 +516,17 @@ uint32_t tsdbGetFileInfo(STsdbRepo *repo, char *name, uint32_t *index, uint32_t magic = pFile->info.magic; char *tfname = strdup(fname); sprintf(name, "tsdb/%s/%s", TSDB_DATA_DIR_NAME, basename(tfname)); - tfree(tfname); + taosMemoryFreeClear(tfname); } else { return 0; } } } } else { // get the named file at the specified index. If not there, return 0 - fname = malloc(256); + fname = taosMemoryMalloc(256); sprintf(fname, "%s/vnode/vnode%d/%s", tfsGetPrimaryPath(pRepo->pTfs), REPO_ID(pRepo), name); if (access(fname, F_OK) != 0) { - tfree(fname); + taosMemoryFreeClear(fname); return 0; } if (*index == TSDB_META_FILE_INDEX) { // get meta file @@ -536,19 +536,19 @@ uint32_t tsdbGetFileInfo(STsdbRepo *repo, char *name, uint32_t *index, uint32_t sprintf(tfname, "vnode/vnode%d/tsdb/%s/%s", REPO_ID(pRepo), TSDB_DATA_DIR_NAME, basename(name)); tsdbGetFileInfoImpl(tfname, &magic, size); } - tfree(fname); + taosMemoryFreeClear(fname); return magic; } if (stat(fname, &fState) < 0) { - tfree(fname); + taosMemoryFreeClear(fname); return 0; } *size = fState.st_size; // magic = *size; - tfree(fname); + taosMemoryFreeClear(fname); return magic; #endif } @@ -674,7 +674,7 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) { } static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) { - STsdbRepo *pRepo = (STsdbRepo *)calloc(1, sizeof(*pRepo)); + STsdbRepo *pRepo = (STsdbRepo *)taosMemoryCalloc(1, sizeof(*pRepo)); if (pRepo == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; @@ -748,7 +748,7 @@ static void tsdbFreeRepo(STsdbRepo *pRepo) { // tsdbFreeMemTable(pRepo->imem); tsem_destroy(&(pRepo->readyToCommit)); taosThreadMutexDestroy(&pRepo->mutex); - free(pRepo); + taosMemoryFree(pRepo); } } @@ -820,7 +820,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea goto out; } - pBlockStatis = calloc(numColumns, sizeof(SDataStatis)); + pBlockStatis = taosMemoryCalloc(numColumns, sizeof(SDataStatis)); if (pBlockStatis == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; err = -1; @@ -886,7 +886,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea // save not-null column uint16_t bytes = IS_VAR_DATA_TYPE(pCol->type) ? varDataTLen(pColData) : pCol->bytes; SDataCol *pLastCol = &(pTable->lastCols[idx]); - pLastCol->pData = malloc(bytes); + pLastCol->pData = taosMemoryMalloc(bytes); pLastCol->bytes = bytes; pLastCol->colId = pCol->colId; memcpy(pLastCol->pData, value, bytes); @@ -907,7 +907,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea out: taosTZfree(row); - tfree(pBlockStatis); + taosMemoryFreeClear(pBlockStatis); if (err == 0 && numColumns <= pTable->restoreColumnNum) { pTable->hasRestoreLastColumn = true; diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index a6df63dfa0..58b4b4602e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -25,7 +25,7 @@ static char * tsdbTbDataGetUid(const void *arg); static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row); STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb) { - STsdbMemTable *pMemTable = (STsdbMemTable *)calloc(1, sizeof(*pMemTable)); + STsdbMemTable *pMemTable = (STsdbMemTable *)taosMemoryCalloc(1, sizeof(*pMemTable)); if (pMemTable == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -38,7 +38,7 @@ STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb) { pMemTable->nRow = 0; pMemTable->pMA = pTsdb->pmaf->create(pTsdb->pmaf); if (pMemTable->pMA == NULL) { - free(pMemTable); + taosMemoryFree(pMemTable); return NULL; } @@ -47,7 +47,7 @@ STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb) { tSkipListCreate(5, TSDB_DATA_TYPE_BIGINT, sizeof(tb_uid_t), tsdbTbDataComp, SL_DISCARD_DUP_KEY, tsdbTbDataGetUid); if (pMemTable->pSlIdx == NULL) { pTsdb->pmaf->destroy(pTsdb->pmaf, pMemTable->pMA); - free(pMemTable); + taosMemoryFree(pMemTable); return NULL; } @@ -55,7 +55,7 @@ STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb) { if (pMemTable->pHashIdx == NULL) { pTsdb->pmaf->destroy(pTsdb->pmaf, pMemTable->pMA); tSkipListDestroy(pMemTable->pSlIdx); - free(pMemTable); + taosMemoryFree(pMemTable); return NULL; } @@ -69,7 +69,7 @@ void tsdbFreeMemTable(STsdb *pTsdb, STsdbMemTable *pMemTable) { if (pMemTable->pMA) { pTsdb->pmaf->destroy(pTsdb->pmaf, pMemTable->pMA); } - free(pMemTable); + taosMemoryFree(pMemTable); } } @@ -376,7 +376,7 @@ static int tsdbMemTableInsertTbData(STsdb *pTsdb, SSubmitBlk *pBlock, int32_t *p } static STbData *tsdbNewTbData(tb_uid_t uid) { - STbData *pTbData = (STbData *)calloc(1, sizeof(*pTbData)); + STbData *pTbData = (STbData *)taosMemoryCalloc(1, sizeof(*pTbData)); if (pTbData == NULL) { return NULL; } @@ -397,14 +397,14 @@ static STbData *tsdbNewTbData(tb_uid_t uid) { // tkeyComparFn, skipListCreateFlags, tsdbGetTsTupleKey); // if (pTableData->pData == NULL) { // terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - // free(pTableData); + // taosMemoryFree(pTableData); // return NULL; // } pTbData->pData = tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), tkeyComparFn, SL_DISCARD_DUP_KEY, tsdbGetTsTupleKey); if (pTbData->pData == NULL) { - free(pTbData); + taosMemoryFree(pTbData); return NULL; } @@ -414,7 +414,7 @@ static STbData *tsdbNewTbData(tb_uid_t uid) { static void tsdbFreeTbData(STbData *pTbData) { if (pTbData) { tSkipListDestroy(pTbData->pData); - free(pTbData); + taosMemoryFree(pTbData); } } @@ -582,7 +582,7 @@ int tsdbTakeMemSnapshot(STsdbRepo *pRepo, SMemSnapshot *pSnapshot, SArray *pATab pSnapshot->mem = &(pSnapshot->mtable); - pSnapshot->mem->tData = (STableData **)calloc(pSnapshot->omem->maxTables, sizeof(STableData *)); + pSnapshot->mem->tData = (STableData **)taosMemoryCalloc(pSnapshot->omem->maxTables, sizeof(STableData *)); if (pSnapshot->mem->tData == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; taosRUnLockLatch(&(pSnapshot->omem->latch)); @@ -629,7 +629,7 @@ void tsdbUnTakeMemSnapShot(STsdbRepo *pRepo, SMemSnapshot *pSnapshot) { tsdbFreeTableData(pTableData); } } - tfree(pSnapshot->mem->tData); + taosMemoryFreeClear(pSnapshot->mem->tData); tsdbUnRefMemTable(pRepo, pSnapshot->omem); } @@ -990,10 +990,10 @@ static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, STSRow* ro TSDB_WLOCK_TABLE(pTable); SDataCol *pDataCol = &(pLatestCols[idx]); if (pDataCol->pData == NULL) { - pDataCol->pData = malloc(pTCol->bytes); + pDataCol->pData = taosMemoryMalloc(pTCol->bytes); pDataCol->bytes = pTCol->bytes; } else if (pDataCol->bytes < pTCol->bytes) { - pDataCol->pData = realloc(pDataCol->pData, pTCol->bytes); + pDataCol->pData = taosMemoryRealloc(pDataCol->pData, pTCol->bytes); pDataCol->bytes = pTCol->bytes; } // the actual value size diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index af3d454a86..bac5255d17 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -355,7 +355,7 @@ static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, STsdbQueryCond* } static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, uint64_t qId, uint64_t taskId) { - STsdbReadHandle* pReadHandle = calloc(1, sizeof(STsdbReadHandle)); + STsdbReadHandle* pReadHandle = taosMemoryCalloc(1, sizeof(STsdbReadHandle)); if (pReadHandle == NULL) { goto _end; } @@ -388,7 +388,7 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, if (pCond->numOfCols > 0) { // allocate buffer in order to load data blocks from file - pReadHandle->statis = calloc(pCond->numOfCols, sizeof(SDataStatis)); + pReadHandle->statis = taosMemoryCalloc(pCond->numOfCols, sizeof(SDataStatis)); if (pReadHandle->statis == NULL) { goto _end; } @@ -597,7 +597,7 @@ static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGr assert(pGroupList); size_t numOfGroup = taosArrayGetSize(pGroupList->pGroupList); - STableGroupInfo* pNew = calloc(1, sizeof(STableGroupInfo)); + STableGroupInfo* pNew = taosMemoryCalloc(1, sizeof(STableGroupInfo)); pNew->pGroupList = taosArrayInit(numOfGroup, POINTER_BYTES); for(int32_t i = 0; i < numOfGroup; ++i) { @@ -1009,7 +1009,7 @@ static int32_t loadBlockInfo(STsdbReadHandle * pTsdbReadHandle, int32_t index, i if (pCheckInfo->compSize < (int32_t)compIndex->len) { assert(compIndex->len > 0); - char* t = realloc(pCheckInfo->pCompInfo, compIndex->len); + char* t = taosMemoryRealloc(pCheckInfo->pCompInfo, compIndex->len); if (t == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; code = TSDB_CODE_TDB_OUT_OF_MEMORY; @@ -1974,15 +1974,15 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) { } static void cleanBlockOrderSupporter(SBlockOrderSupporter* pSupporter, int32_t numOfTables) { - tfree(pSupporter->numOfBlocksPerTable); - tfree(pSupporter->blockIndexArray); + taosMemoryFreeClear(pSupporter->numOfBlocksPerTable); + taosMemoryFreeClear(pSupporter->blockIndexArray); for (int32_t i = 0; i < numOfTables; ++i) { STableBlockInfo* pBlockInfo = pSupporter->pDataBlockInfo[i]; - tfree(pBlockInfo); + taosMemoryFreeClear(pBlockInfo); } - tfree(pSupporter->pDataBlockInfo); + taosMemoryFreeClear(pSupporter->pDataBlockInfo); } static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* param) { @@ -2021,7 +2021,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu if (pTsdbReadHandle->allocSize < size) { pTsdbReadHandle->allocSize = (int32_t)size; - char* tmp = realloc(pTsdbReadHandle->pDataBlockInfo, pTsdbReadHandle->allocSize); + char* tmp = taosMemoryRealloc(pTsdbReadHandle->pDataBlockInfo, pTsdbReadHandle->allocSize); if (tmp == NULL) { return TSDB_CODE_TDB_OUT_OF_MEMORY; } @@ -2037,9 +2037,9 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu SBlockOrderSupporter sup = {0}; sup.numOfTables = numOfTables; - sup.numOfBlocksPerTable = calloc(1, sizeof(int32_t) * numOfTables); - sup.blockIndexArray = calloc(1, sizeof(int32_t) * numOfTables); - sup.pDataBlockInfo = calloc(1, POINTER_BYTES * numOfTables); + sup.numOfBlocksPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables); + sup.blockIndexArray = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables); + sup.pDataBlockInfo = taosMemoryCalloc(1, POINTER_BYTES * numOfTables); if (sup.numOfBlocksPerTable == NULL || sup.blockIndexArray == NULL || sup.pDataBlockInfo == NULL) { cleanBlockOrderSupporter(&sup, 0); @@ -2058,7 +2058,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu SBlock* pBlock = pTableCheck->pCompInfo->blocks; sup.numOfBlocksPerTable[numOfQualTables] = pTableCheck->numOfBlocks; - char* buf = malloc(sizeof(STableBlockInfo) * pTableCheck->numOfBlocks); + char* buf = taosMemoryMalloc(sizeof(STableBlockInfo) * pTableCheck->numOfBlocks); if (buf == NULL) { cleanBlockOrderSupporter(&sup, numOfQualTables); return TSDB_CODE_TDB_OUT_OF_MEMORY; @@ -2128,7 +2128,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu tsdbDebug("%p %d data blocks sort completed, %s", pTsdbReadHandle, cnt, pTsdbReadHandle->idStr); cleanBlockOrderSupporter(&sup, numOfTables); - free(pTree); + taosMemoryFree(pTree); return TSDB_CODE_SUCCESS; } @@ -2536,12 +2536,12 @@ static void destroyHelper(void* param) { // tQueryInfo* pInfo = (tQueryInfo*)param; // if (pInfo->optr != TSDB_RELATION_IN) { -// tfree(pInfo->q); +// taosMemoryFreeClear(pInfo->q); // } else { // taosHashCleanup((SHashObj *)(pInfo->q)); // } - free(param); + taosMemoryFree(param); } #define TSDB_PREV_ROW 0x1 @@ -2616,7 +2616,7 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // return false; // } mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, pRow, NULL, numOfCols, pCheckInfo->tableId, NULL, NULL, true); - tfree(pRow); + taosMemoryFreeClear(pRow); // update the last key value pCheckInfo->lastKey = key + step; @@ -2904,7 +2904,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // // SColumnInfoData colInfo = {{0}, 0}; // colInfo.info = pCol->info; -// colInfo.pData = calloc(1, pCol->info.bytes); +// colInfo.pData = taosMemoryCalloc(1, pCol->info.bytes); // if (colInfo.pData == NULL) { // terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; // goto out_of_memory; @@ -2923,7 +2923,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // cond.twindow = (STimeWindow){pTsdbReadHandle->window.skey, INT64_MAX}; // } // -// cond.colList = calloc(cond.numOfCols, sizeof(SColumnInfo)); +// cond.colList = taosMemoryCalloc(cond.numOfCols, sizeof(SColumnInfo)); // if (cond.colList == NULL) { // terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; // goto out_of_memory; @@ -2935,7 +2935,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // } // // pSecQueryHandle = tsdbQueryTablesImpl(pTsdbReadHandle->pTsdb, &cond, pTsdbReadHandle->idStr, pMemRef); -// tfree(cond.colList); +// taosMemoryFreeClear(cond.colList); // // // current table, only one table // STableCheckInfo* pCurrent = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); @@ -3294,7 +3294,7 @@ void filterPrepare(void* expr, void* param) { return; } - pExpr->_node.info = calloc(1, sizeof(tQueryInfo)); + pExpr->_node.info = taosMemoryCalloc(1, sizeof(tQueryInfo)); STSchema* pTSSchema = (STSchema*) param; tQueryInfo* pInfo = pExpr->_node.info; @@ -3327,7 +3327,7 @@ void filterPrepare(void* expr, void* param) { size = pSchema->bytes; } // to make sure tonchar does not cause invalid write, since the '\0' needs at least sizeof(TdUcs4) space. - pInfo->q = calloc(1, size + TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + pInfo->q = taosMemoryCalloc(1, size + TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); tVariantDump(pCond, pInfo->q, pSchema->type, true); } } @@ -3613,7 +3613,7 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch // if (tagExpr != NULL) { // CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, tagExpr, NULL); // tExprNode* tbnameExpr = expr; -// expr = calloc(1, sizeof(tExprNode)); +// expr = taosMemoryCalloc(1, sizeof(tExprNode)); // if (expr == NULL) { // THROW( TSDB_CODE_TDB_OUT_OF_MEMORY ); // } @@ -3727,7 +3727,7 @@ static void* doFreeColumnInfoData(SArray* pColumnInfoData) { size_t cols = taosArrayGetSize(pColumnInfoData); for (int32_t i = 0; i < cols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pColumnInfoData, i); - tfree(pColInfo->pData); + taosMemoryFreeClear(pColInfo->pData); } taosArrayDestroy(pColumnInfoData); @@ -3740,7 +3740,7 @@ static void* destroyTableCheckInfo(SArray* pTableCheckInfo) { STableCheckInfo* p = taosArrayGet(pTableCheckInfo, i); destroyTableMemIterator(p); - tfree(p->pCompInfo); + taosMemoryFreeClear(p->pCompInfo); } taosArrayDestroy(pTableCheckInfo); @@ -3757,8 +3757,8 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { pTsdbReadHandle->pColumns = doFreeColumnInfoData(pTsdbReadHandle->pColumns); taosArrayDestroy(pTsdbReadHandle->defaultLoadColumn); - tfree(pTsdbReadHandle->pDataBlockInfo); - tfree(pTsdbReadHandle->statis); + taosMemoryFreeClear(pTsdbReadHandle->pDataBlockInfo); + taosMemoryFreeClear(pTsdbReadHandle->statis); if (!emptyQueryTimewindow(pTsdbReadHandle)) { // tsdbMayUnTakeMemSnapshot(pTsdbReadHandle); @@ -3783,7 +3783,7 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { tsdbDebug("%p :io-cost summary: head-file read cnt:%"PRIu64", head-file time:%"PRIu64" us, statis-info:%"PRId64" us, datablock:%" PRId64" us, check data:%"PRId64" us, %s", pTsdbReadHandle, pCost->headFileLoad, pCost->headFileLoadTime, pCost->statisInfoLoadTime, pCost->blockLoadTime, pCost->checkForNextTime, pTsdbReadHandle->idStr); - tfree(pTsdbReadHandle); + taosMemoryFreeClear(pTsdbReadHandle); } #if 0 @@ -3842,15 +3842,15 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) { if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL || optr == TSDB_RELATION_EQUAL || optr == TSDB_RELATION_NOT_EQUAL) { - pCond->start = calloc(1, sizeof(SEndPoint)); + pCond->start = taosMemoryCalloc(1, sizeof(SEndPoint)); pCond->start->optr = queryColInfo->optr; pCond->start->v = queryColInfo->q; } else if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) { - pCond->end = calloc(1, sizeof(SEndPoint)); + pCond->end = taosMemoryCalloc(1, sizeof(SEndPoint)); pCond->end->optr = queryColInfo->optr; pCond->end->v = queryColInfo->q; } else if (optr == TSDB_RELATION_IN) { - pCond->start = calloc(1, sizeof(SEndPoint)); + pCond->start = taosMemoryCalloc(1, sizeof(SEndPoint)); pCond->start->optr = queryColInfo->optr; pCond->start->v = queryColInfo->q; } else if (optr == TSDB_RELATION_LIKE) { @@ -3996,8 +3996,8 @@ static void queryIndexedColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SAr } } - free(cond.start); - free(cond.end); + taosMemoryFree(cond.start); + taosMemoryFree(cond.end); tSkipListDestroyIter(iter); } diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index a10252e286..0873e8edc1 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -169,7 +169,7 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) { static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) { SSmaEnv *pEnv = NULL; - pEnv = (SSmaEnv *)calloc(1, sizeof(SSmaEnv)); + pEnv = (SSmaEnv *)taosMemoryCalloc(1, sizeof(SSmaEnv)); if (pEnv == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -178,7 +178,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) int code = taosThreadRwlockInit(&(pEnv->lock), NULL); if (code) { terrno = TAOS_SYSTEM_ERROR(code); - free(pEnv); + taosMemoryFree(pEnv); return NULL; } @@ -230,8 +230,8 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaE void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) { if (pSmaEnv) { tsdbDestroySmaState(pSmaEnv->pStat); - tfree(pSmaEnv->pStat); - tfree(pSmaEnv->path); + taosMemoryFreeClear(pSmaEnv->pStat); + taosMemoryFreeClear(pSmaEnv->path); taosThreadRwlockDestroy(&(pSmaEnv->lock)); tsdbCloseBDBEnv(pSmaEnv->dbEnv); } @@ -239,7 +239,7 @@ void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) { void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv) { tsdbDestroySmaEnv(pSmaEnv); - tfree(pSmaEnv); + taosMemoryFreeClear(pSmaEnv); return NULL; } @@ -271,7 +271,7 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) { * tsdbInitSmaStat invoked in other multithread environment later. */ if (*pSmaStat == NULL) { - *pSmaStat = (SSmaStat *)calloc(1, sizeof(SSmaStat)); + *pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat)); if (*pSmaStat == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_FAILED; @@ -281,7 +281,7 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) { taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if ((*pSmaStat)->smaStatItems == NULL) { - tfree(*pSmaStat); + taosMemoryFreeClear(*pSmaStat); return TSDB_CODE_FAILED; } } @@ -291,13 +291,13 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) { static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) { SSmaStatItem *pItem = NULL; - pItem = (SSmaStatItem *)calloc(1, sizeof(SSmaStatItem)); + pItem = (SSmaStatItem *)taosMemoryCalloc(1, sizeof(SSmaStatItem)); if (pItem) { pItem->state = state; pItem->expiredWindows = taosHashInit(SMA_STATE_ITEM_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP), true, HASH_ENTRY_LOCK); if (!pItem->expiredWindows) { - tfree(pItem); + taosMemoryFreeClear(pItem); } } return pItem; @@ -306,9 +306,9 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) { static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) { if (pSmaStatItem != NULL) { tdDestroyTSma(pSmaStatItem->pSma); - tfree(pSmaStatItem->pSma); + taosMemoryFreeClear(pSmaStatItem->pSma); taosHashCleanup(pSmaStatItem->expiredWindows); - tfree(pSmaStatItem); + taosMemoryFreeClear(pSmaStatItem); } return NULL; } @@ -406,7 +406,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t if (pSma == NULL) { terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META; taosHashCleanup(pItem->expiredWindows); - free(pItem); + taosMemoryFree(pItem); tsdbWarn("vgId:%d update expired window failed for smaIndex %" PRIi64 " since %s", REPO_ID(pTsdb), indexUid, tstrerror(terrno)); return TSDB_CODE_FAILED; @@ -416,7 +416,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t if (taosHashPut(pItemsHash, &indexUid, sizeof(indexUid), &pItem, sizeof(pItem)) != 0) { // If error occurs during put smaStatItem, free the resources of pItem taosHashCleanup(pItem->expiredWindows); - free(pItem); + taosMemoryFree(pItem); return TSDB_CODE_FAILED; } } @@ -430,7 +430,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t // 2) This would solve the inconsistency to some extent, but not completely, unless we record all expired // windows failed to put into hash table. taosHashCleanup(pItem->expiredWindows); - tfree(pItem->pSma); + taosMemoryFreeClear(pItem->pSma); taosHashRemove(pItemsHash, &indexUid, sizeof(indexUid)); return TSDB_CODE_FAILED; } @@ -1237,7 +1237,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ tsdbWarn("vgId:%d get sma data v[%d]=%" PRIi64, REPO_ID(pTsdb), v, *(int64_t *)POINTER_SHIFT(result, v)); } #endif - tfree(result); // TODO: fill the result to output + taosMemoryFreeClear(result); // TODO: fill the result to output #if 0 int32_t nResult = 0; diff --git a/source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c b/source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c index 14b9a5124f..ab0da1451d 100644 --- a/source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c +++ b/source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c @@ -19,7 +19,7 @@ static SVArenaNode *vArenaNodeNew(uint64_t capacity); static void vArenaNodeFree(SVArenaNode *pNode); SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { - SVMemAllocator *pVMA = (SVMemAllocator *)malloc(sizeof(*pVMA)); + SVMemAllocator *pVMA = (SVMemAllocator *)taosMemoryMalloc(sizeof(*pVMA)); if (pVMA == NULL) { return NULL; } @@ -31,7 +31,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { pVMA->pNode = vArenaNodeNew(capacity); if (pVMA->pNode == NULL) { - free(pVMA); + taosMemoryFree(pVMA); return NULL; } @@ -48,7 +48,7 @@ void vmaDestroy(SVMemAllocator *pVMA) { vArenaNodeFree(pNode); } - free(pVMA); + taosMemoryFree(pVMA); } } @@ -99,7 +99,7 @@ bool vmaIsFull(SVMemAllocator *pVMA) { static SVArenaNode *vArenaNodeNew(uint64_t capacity) { SVArenaNode *pNode = NULL; - pNode = (SVArenaNode *)malloc(sizeof(*pNode) + capacity); + pNode = (SVArenaNode *)taosMemoryMalloc(sizeof(*pNode) + capacity); if (pNode == NULL) { return NULL; } @@ -112,6 +112,6 @@ static SVArenaNode *vArenaNodeNew(uint64_t capacity) { static void vArenaNodeFree(SVArenaNode *pNode) { if (pNode) { - free(pNode); + taosMemoryFree(pNode); } } diff --git a/source/dnode/vnode/src/vnd/vnodeBufferPool.c b/source/dnode/vnode/src/vnd/vnodeBufferPool.c index 3b43fd82f6..5be88cdc2e 100644 --- a/source/dnode/vnode/src/vnd/vnodeBufferPool.c +++ b/source/dnode/vnode/src/vnd/vnodeBufferPool.c @@ -34,7 +34,7 @@ static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocato int vnodeOpenBufPool(SVnode *pVnode) { uint64_t capacity; - if ((pVnode->pBufPool = (SVBufPool *)calloc(1, sizeof(SVBufPool))) == NULL) { + if ((pVnode->pBufPool = (SVBufPool *)taosMemoryCalloc(1, sizeof(SVBufPool))) == NULL) { /* TODO */ return -1; } @@ -57,7 +57,7 @@ int vnodeOpenBufPool(SVnode *pVnode) { TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA); } - pVnode->pBufPool->pMAF = (SMemAllocatorFactory *)malloc(sizeof(SMemAllocatorFactory)); + pVnode->pBufPool->pMAF = (SMemAllocatorFactory *)taosMemoryMalloc(sizeof(SMemAllocatorFactory)); if (pVnode->pBufPool->pMAF == NULL) { // TODO: handle error return -1; @@ -71,7 +71,7 @@ int vnodeOpenBufPool(SVnode *pVnode) { void vnodeCloseBufPool(SVnode *pVnode) { if (pVnode->pBufPool) { - tfree(pVnode->pBufPool->pMAF); + taosMemoryFreeClear(pVnode->pBufPool->pMAF); vmaDestroy(pVnode->pBufPool->inuse); while (true) { @@ -88,7 +88,7 @@ void vnodeCloseBufPool(SVnode *pVnode) { vmaDestroy(pVMA); } - free(pVnode->pBufPool); + taosMemoryFree(pVnode->pBufPool); pVnode->pBufPool = NULL; } } @@ -161,7 +161,7 @@ static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pMAF) { SVnode * pVnode = (SVnode *)(pMAF->impl); SVMAWrapper * pWrapper; - pMA = (SMemAllocator *)calloc(1, sizeof(*pMA) + sizeof(SVMAWrapper)); + pMA = (SMemAllocator *)taosMemoryCalloc(1, sizeof(*pMA) + sizeof(SVMAWrapper)); if (pMA == NULL) { return NULL; } @@ -182,7 +182,7 @@ static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA) { SVnode * pVnode = pWrapper->pVnode; SVMemAllocator *pVMA = pWrapper->pVMA; - free(pMA); + taosMemoryFree(pMA); if (--pVMA->_ref.val == 0) { TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA); vmaReset(pVMA); diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index bc7a8460b8..696c5f39f6 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -24,7 +24,7 @@ int vnodeAsyncCommit(SVnode *pVnode) { vnodeWaitCommit(pVnode); vnodeBufPoolSwitch(pVnode); - SVnodeTask *pTask = (SVnodeTask *)malloc(sizeof(*pTask)); + SVnodeTask *pTask = (SVnodeTask *)taosMemoryMalloc(sizeof(*pTask)); pTask->execute = vnodeCommit; // TODO pTask->arg = pVnode; // TODO diff --git a/source/dnode/vnode/src/vnd/vnodeMain.c b/source/dnode/vnode/src/vnd/vnodeMain.c index 70f4117976..91c6e4d263 100644 --- a/source/dnode/vnode/src/vnd/vnodeMain.c +++ b/source/dnode/vnode/src/vnd/vnodeMain.c @@ -72,7 +72,7 @@ void vnodeDestroy(const char *path) { taosRemoveDir(path); } static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) { SVnode *pVnode = NULL; - pVnode = (SVnode *)calloc(1, sizeof(*pVnode)); + pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode)); if (pVnode == NULL) { // TODO return NULL; @@ -92,8 +92,8 @@ static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) { static void vnodeFree(SVnode *pVnode) { if (pVnode) { tsem_destroy(&(pVnode->canCommit)); - tfree(pVnode->path); - free(pVnode); + taosMemoryFreeClear(pVnode->path); + taosMemoryFree(pVnode); } } diff --git a/source/dnode/vnode/src/vnd/vnodeMgr.c b/source/dnode/vnode/src/vnd/vnodeMgr.c index 920b5b0947..8f7d5713ab 100644 --- a/source/dnode/vnode/src/vnd/vnodeMgr.c +++ b/source/dnode/vnode/src/vnd/vnodeMgr.c @@ -29,7 +29,7 @@ int vnodeInit() { // Start commit handers vnodeMgr.nthreads = tsNumOfCommitThreads; - vnodeMgr.threads = calloc(vnodeMgr.nthreads, sizeof(TdThread)); + vnodeMgr.threads = taosMemoryCalloc(vnodeMgr.nthreads, sizeof(TdThread)); if (vnodeMgr.threads == NULL) { return -1; } @@ -65,7 +65,7 @@ void vnodeCleanup() { taosThreadJoin(vnodeMgr.threads[i], NULL); } - tfree(vnodeMgr.threads); + taosMemoryFreeClear(vnodeMgr.threads); taosThreadCondDestroy(&(vnodeMgr.hasTask)); taosThreadMutexDestroy(&(vnodeMgr.mutex)); } @@ -107,7 +107,7 @@ static void* loop(void* arg) { taosThreadMutexUnlock(&(vnodeMgr.mutex)); (*(pTask->execute))(pTask->arg); - free(pTask); + taosMemoryFree(pTask); } return NULL; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index a3258044c8..6b5eb5bd6f 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -141,7 +141,7 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { pTagSchema = NULL; } - metaRsp.pSchemas = calloc(nCols + nTagCols, sizeof(SSchema)); + metaRsp.pSchemas = taosMemoryCalloc(nCols + nTagCols, sizeof(SSchema)); if (metaRsp.pSchemas == NULL) { code = TSDB_CODE_VND_OUT_OF_MEMORY; goto _exit; @@ -182,19 +182,19 @@ _exit: tFreeSTableMetaRsp(&metaRsp); if (pSW != NULL) { - tfree(pSW->pSchema); - tfree(pSW); + taosMemoryFreeClear(pSW->pSchema); + taosMemoryFreeClear(pSW); } if (pTbCfg) { - tfree(pTbCfg->name); + taosMemoryFreeClear(pTbCfg->name); if (pTbCfg->type == META_SUPER_TABLE) { - free(pTbCfg->stbCfg.pTagSchema); + taosMemoryFree(pTbCfg->stbCfg.pTagSchema); } else if (pTbCfg->type == META_SUPER_TABLE) { kvRowFree(pTbCfg->ctbCfg.pTag); } - tfree(pTbCfg); + taosMemoryFreeClear(pTbCfg); } rpcMsg.handle = pMsg->handle; @@ -210,7 +210,7 @@ _exit: static void freeItemHelper(void *pItem) { char *p = *(char **)pItem; - free(p); + taosMemoryFree(p); } /** @@ -230,7 +230,7 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { taosArrayPush(pArray, &name); totalLen += strlen(name); } else { - tfree(name); + taosMemoryFreeClear(name); } numOfTables++; @@ -260,7 +260,7 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { STR_TO_VARSTR(p, n); p += (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); - // free(n); + // taosMemoryFree(n); } pFetchRsp->numOfRows = htonl(numOfTables); diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index 3ef45ecb09..e0be9ed89a 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -72,9 +72,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } // TODO: maybe need to clear the request struct - free(vCreateTbReq.stbCfg.pSchema); - free(vCreateTbReq.stbCfg.pTagSchema); - free(vCreateTbReq.name); + taosMemoryFree(vCreateTbReq.stbCfg.pSchema); + taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); + taosMemoryFree(vCreateTbReq.name); break; } case TDMT_VND_CREATE_TABLE: { @@ -101,14 +101,14 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // TODO: handle error vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name); } - free(pCreateTbReq->name); + taosMemoryFree(pCreateTbReq->name); if (pCreateTbReq->type == TD_SUPER_TABLE) { - free(pCreateTbReq->stbCfg.pSchema); - free(pCreateTbReq->stbCfg.pTagSchema); + taosMemoryFree(pCreateTbReq->stbCfg.pSchema); + taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); } else if (pCreateTbReq->type == TD_CHILD_TABLE) { - free(pCreateTbReq->ctbCfg.pTag); + taosMemoryFree(pCreateTbReq->ctbCfg.pTag); } else { - free(pCreateTbReq->ntbCfg.pSchema); + taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); } } @@ -120,7 +120,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { tSerializeSVCreateTbBatchRsp(msg, contLen, &vCreateTbBatchRsp); taosArrayDestroy(vCreateTbBatchRsp.rspList); - *pRsp = calloc(1, sizeof(SRpcMsg)); + *pRsp = taosMemoryCalloc(1, sizeof(SRpcMsg)); (*pRsp)->msgType = TDMT_VND_CREATE_TABLE_RSP; (*pRsp)->pCont = msg; (*pRsp)->contLen = contLen; @@ -133,9 +133,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { SVCreateTbReq vAlterTbReq = {0}; vTrace("vgId:%d, process alter stb req", pVnode->vgId); tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vAlterTbReq); - free(vAlterTbReq.stbCfg.pSchema); - free(vAlterTbReq.stbCfg.pTagSchema); - free(vAlterTbReq.name); + taosMemoryFree(vAlterTbReq.stbCfg.pSchema); + taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); + taosMemoryFree(vAlterTbReq.name); break; } case TDMT_VND_DROP_STB: diff --git a/source/dnode/vnode/test/tqMetaTest.cpp b/source/dnode/vnode/test/tqMetaTest.cpp index 4f15185254..627dbc6f18 100644 --- a/source/dnode/vnode/test/tqMetaTest.cpp +++ b/source/dnode/vnode/test/tqMetaTest.cpp @@ -12,7 +12,7 @@ struct Foo { int FooSerializer(const void* pObj, STqSerializedHead** ppHead) { Foo* foo = (Foo*)pObj; if ((*ppHead) == NULL || (*ppHead)->ssize < sizeof(STqSerializedHead) + sizeof(int32_t)) { - *ppHead = (STqSerializedHead*)realloc(*ppHead, sizeof(STqSerializedHead) + sizeof(int32_t)); + *ppHead = (STqSerializedHead*)taosMemoryRealloc(*ppHead, sizeof(STqSerializedHead) + sizeof(int32_t)); (*ppHead)->ssize = sizeof(STqSerializedHead) + sizeof(int32_t); } *(int32_t*)(*ppHead)->content = foo->a; @@ -21,14 +21,14 @@ int FooSerializer(const void* pObj, STqSerializedHead** ppHead) { const void* FooDeserializer(const STqSerializedHead* pHead, void** ppObj) { if (*ppObj == NULL) { - *ppObj = realloc(*ppObj, sizeof(int32_t)); + *ppObj = taosMemoryRealloc(*ppObj, sizeof(int32_t)); } Foo* pFoo = *(Foo**)ppObj; pFoo->a = *(int32_t*)pHead->content; return NULL; } -void FooDeleter(void* pObj) { free(pObj); } +void FooDeleter(void* pObj) { taosMemoryFree(pObj); } class TqMetaUpdateAppendTest : public ::testing::Test { protected: @@ -58,7 +58,7 @@ TEST_F(TqMetaUpdateAppendTest, copyPutTest) { } TEST_F(TqMetaUpdateAppendTest, persistTest) { - Foo* pFoo = (Foo*)malloc(sizeof(Foo)); + Foo* pFoo = (Foo*)taosMemoryMalloc(sizeof(Foo)); pFoo->a = 2; tqHandleMovePut(pMeta, 1, pFoo); Foo* pBar = (Foo*)tqHandleGet(pMeta, 1); @@ -82,7 +82,7 @@ TEST_F(TqMetaUpdateAppendTest, persistTest) { } TEST_F(TqMetaUpdateAppendTest, uncommittedTest) { - Foo* pFoo = (Foo*)malloc(sizeof(Foo)); + Foo* pFoo = (Foo*)taosMemoryMalloc(sizeof(Foo)); pFoo->a = 3; tqHandleMovePut(pMeta, 1, pFoo); @@ -91,7 +91,7 @@ TEST_F(TqMetaUpdateAppendTest, uncommittedTest) { } TEST_F(TqMetaUpdateAppendTest, abortTest) { - Foo* pFoo = (Foo*)malloc(sizeof(Foo)); + Foo* pFoo = (Foo*)taosMemoryMalloc(sizeof(Foo)); pFoo->a = 3; tqHandleMovePut(pMeta, 1, pFoo); @@ -104,7 +104,7 @@ TEST_F(TqMetaUpdateAppendTest, abortTest) { } TEST_F(TqMetaUpdateAppendTest, deleteTest) { - Foo* pFoo = (Foo*)malloc(sizeof(Foo)); + Foo* pFoo = (Foo*)taosMemoryMalloc(sizeof(Foo)); pFoo->a = 3; tqHandleMovePut(pMeta, 1, pFoo); @@ -135,12 +135,12 @@ TEST_F(TqMetaUpdateAppendTest, deleteTest) { } TEST_F(TqMetaUpdateAppendTest, intxnPersist) { - Foo* pFoo = (Foo*)malloc(sizeof(Foo)); + Foo* pFoo = (Foo*)taosMemoryMalloc(sizeof(Foo)); pFoo->a = 3; tqHandleMovePut(pMeta, 1, pFoo); tqHandleCommit(pMeta, 1); - Foo* pBar = (Foo*)malloc(sizeof(Foo)); + Foo* pBar = (Foo*)taosMemoryMalloc(sizeof(Foo)); pBar->a = 4; tqHandleMovePut(pMeta, 1, pBar); diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index c13ae83150..c9488549c6 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -51,12 +51,12 @@ TEST(testCase, unionEncodeDecodeTest) { sut.type = 1; sut.nBSmaCols = 2; - sut.pBSmaCols = (col_id_t*)malloc(sut.nBSmaCols * sizeof(col_id_t)); + sut.pBSmaCols = (col_id_t*)taosMemoryMalloc(sut.nBSmaCols * sizeof(col_id_t)); for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { sut.pBSmaCols[i] = i + 100; } - void* buf = malloc(1024); + void* buf = taosMemoryMalloc(1024); void * pBuf = buf; int32_t tlen = 0; tlen += taosEncodeFixedU8(&buf, sut.info); @@ -69,7 +69,7 @@ TEST(testCase, unionEncodeDecodeTest) { pBuf = taosDecodeFixedU8(pBuf, &dut.info); pBuf = taosDecodeFixedI16(pBuf, &dut.nBSmaCols); if(dut.nBSmaCols > 0) { - dut.pBSmaCols = (col_id_t*)malloc(dut.nBSmaCols * sizeof(col_id_t)); + dut.pBSmaCols = (col_id_t*)taosMemoryMalloc(dut.nBSmaCols * sizeof(col_id_t)); for(col_id_t i=0; i < dut.nBSmaCols; ++i) { pBuf = taosDecodeFixedI16(pBuf, dut.pBSmaCols + i); } @@ -105,7 +105,7 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) { STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma}; uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper); - void *buf = calloc(1, bufLen); + void *buf = taosMemoryCalloc(1, bufLen); ASSERT_NE(buf, nullptr); STSmaWrapper *pSW = (STSmaWrapper *)buf; @@ -140,7 +140,7 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) { } // resource release - tfree(pSW); + taosMemoryFreeClear(pSW); tdDestroyTSma(&tSma); tdDestroyTSmaWrapper(&dstTSmaWrapper); } @@ -171,12 +171,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { tSma.tableUid = tbUid; tSma.exprLen = strlen(expr); - tSma.expr = (char *)calloc(1, tSma.exprLen + 1); + tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1); ASSERT_NE(tSma.expr, nullptr); tstrncpy(tSma.expr, expr, tSma.exprLen + 1); tSma.tagsFilterLen = strlen(tagsFilter); - tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1); + tSma.tagsFilter = (char *)taosMemoryCalloc(tSma.tagsFilterLen + 1, 1); ASSERT_NE(tSma.tagsFilter, nullptr); tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1); @@ -213,7 +213,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); ASSERT_EQ(qSmaCfg->tableUid, tSma.tableUid); tdDestroyTSma(qSmaCfg); - tfree(qSmaCfg); + taosMemoryFreeClear(qSmaCfg); qSmaCfg = metaGetSmaInfoByIndex(pMeta, indexUid2); assert(qSmaCfg != NULL); @@ -224,7 +224,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); ASSERT_EQ(qSmaCfg->interval, tSma.interval); tdDestroyTSma(qSmaCfg); - tfree(qSmaCfg); + taosMemoryFreeClear(qSmaCfg); // get index name by table uid SMSmaCursor *pSmaCur = metaOpenSmaCursor(pMeta, tbUid); @@ -259,7 +259,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ASSERT_EQ((pSW->tSma + 1)->tableUid, tbUid); tdDestroyTSmaWrapper(pSW); - tfree(pSW); + taosMemoryFreeClear(pSW); // get all sma table uids SArray *pUids = metaGetSmaTbUids(pMeta, false); @@ -309,12 +309,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { tSma.tableUid = tbUid; tSma.exprLen = strlen(expr); - tSma.expr = (char *)calloc(1, tSma.exprLen + 1); + tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1); ASSERT_NE(tSma.expr, nullptr); tstrncpy(tSma.expr, expr, tSma.exprLen + 1); tSma.tagsFilterLen = strlen(tagsFilter); - tSma.tagsFilter = (char *)calloc(1, tSma.tagsFilterLen + 1); + tSma.tagsFilter = (char *)taosMemoryCalloc(1, tSma.tagsFilterLen + 1); ASSERT_NE(tSma.tagsFilter, nullptr); tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1); @@ -331,7 +331,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { // step 2: insert data STSmaDataWrapper *pSmaData = NULL; - STsdb * pTsdb = (STsdb *)calloc(1, sizeof(STsdb)); + STsdb * pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb)); STsdbCfg * pCfg = &pTsdb->config; pTsdb->pMeta = pMeta; @@ -367,7 +367,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks); ASSERT_NE(pTsdb->pTfs, nullptr); - char *msg = (char *)calloc(1, 100); + char *msg = (char *)taosMemoryCalloc(1, 100); ASSERT_NE(msg, nullptr); ASSERT_EQ(tsdbUpdateSmaWindow(pTsdb, msg), 0); @@ -443,7 +443,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt); // release data - tfree(msg); + taosMemoryFreeClear(msg); taosTZfree(buf); // release meta tdDestroyTSma(&tSma); diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 8f67482650..7bbff05b4b 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -242,7 +242,7 @@ void ctgFreeMetaRent(SCtgRentMgmt *mgmt) { } } - tfree(mgmt->slots); + taosMemoryFreeClear(mgmt->slots); } @@ -272,7 +272,7 @@ void ctgFreeVgInfo(SDBVgInfo *vgInfo) { vgInfo->vgHash = NULL; } - tfree(vgInfo); + taosMemoryFreeClear(vgInfo); } void ctgFreeDbCache(SCtgDBCache *dbCache) { @@ -307,7 +307,7 @@ void ctgFreeHandle(SCatalog* pCtg) { taosHashCleanup(pCtg->dbCache); } - free(pCtg); + taosMemoryFree(pCtg); } @@ -338,14 +338,14 @@ void ctgPopAction(SCtgMetaAction **action) { CTG_QUEUE_SUB(); - tfree(orig); + taosMemoryFreeClear(orig); *action = &node->action; } int32_t ctgPushAction(SCatalog* pCtg, SCtgMetaAction *action) { - SCtgQNode *node = calloc(1, sizeof(SCtgQNode)); + SCtgQNode *node = taosMemoryCalloc(1, sizeof(SCtgQNode)); if (NULL == node) { qError("calloc %d failed", (int32_t)sizeof(SCtgQNode)); CTG_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -378,7 +378,7 @@ int32_t ctgPushAction(SCatalog* pCtg, SCtgMetaAction *action) { int32_t ctgPushRmDBMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId) { int32_t code = 0; SCtgMetaAction action= {.act = CTG_ACT_REMOVE_DB}; - SCtgRemoveDBMsg *msg = malloc(sizeof(SCtgRemoveDBMsg)); + SCtgRemoveDBMsg *msg = taosMemoryMalloc(sizeof(SCtgRemoveDBMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveDBMsg)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -401,7 +401,7 @@ int32_t ctgPushRmDBMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId) _return: - tfree(action.data); + taosMemoryFreeClear(action.data); CTG_RET(code); } @@ -409,7 +409,7 @@ _return: int32_t ctgPushRmStbMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid) { int32_t code = 0; SCtgMetaAction action= {.act = CTG_ACT_REMOVE_STB}; - SCtgRemoveStbMsg *msg = malloc(sizeof(SCtgRemoveStbMsg)); + SCtgRemoveStbMsg *msg = taosMemoryMalloc(sizeof(SCtgRemoveStbMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveStbMsg)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -429,7 +429,7 @@ int32_t ctgPushRmStbMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId _return: - tfree(action.data); + taosMemoryFreeClear(action.data); CTG_RET(code); } @@ -438,7 +438,7 @@ _return: int32_t ctgPushRmTblMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName) { int32_t code = 0; SCtgMetaAction action= {.act = CTG_ACT_REMOVE_TBL}; - SCtgRemoveTblMsg *msg = malloc(sizeof(SCtgRemoveTblMsg)); + SCtgRemoveTblMsg *msg = taosMemoryMalloc(sizeof(SCtgRemoveTblMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveTblMsg)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -457,14 +457,14 @@ int32_t ctgPushRmTblMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId _return: - tfree(action.data); + taosMemoryFreeClear(action.data); CTG_RET(code); } int32_t ctgPushUpdateVgMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, SDBVgInfo* dbInfo, bool syncReq) { int32_t code = 0; SCtgMetaAction action= {.act = CTG_ACT_UPDATE_VG, .syncReq = syncReq}; - SCtgUpdateVgMsg *msg = malloc(sizeof(SCtgUpdateVgMsg)); + SCtgUpdateVgMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateVgMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateVgMsg)); ctgFreeVgInfo(dbInfo); @@ -490,14 +490,14 @@ int32_t ctgPushUpdateVgMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t d _return: ctgFreeVgInfo(dbInfo); - tfree(action.data); + taosMemoryFreeClear(action.data); CTG_RET(code); } int32_t ctgPushUpdateTblMsgInQueue(SCatalog* pCtg, STableMetaOutput *output, bool syncReq) { int32_t code = 0; SCtgMetaAction action= {.act = CTG_ACT_UPDATE_TBL}; - SCtgUpdateTblMsg *msg = malloc(sizeof(SCtgUpdateTblMsg)); + SCtgUpdateTblMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateTblMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateTblMsg)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -519,7 +519,7 @@ int32_t ctgPushUpdateTblMsgInQueue(SCatalog* pCtg, STableMetaOutput *output, boo _return: - tfree(msg); + taosMemoryFreeClear(msg); CTG_RET(code); } @@ -818,7 +818,7 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable CTG_UNLOCK(CTG_READ, &dbCache->tbCache.stbLock); ctgReleaseDBCache(pCtg, dbCache); ctgError("stb not in stbCache, suid:%"PRIx64, tbMeta->suid); - tfree(*pTableMeta); + taosMemoryFreeClear(*pTableMeta); *exist = 0; return TSDB_CODE_SUCCESS; } @@ -826,13 +826,13 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable if ((*stbMeta)->suid != tbMeta->suid) { CTG_UNLOCK(CTG_READ, &dbCache->tbCache.stbLock); ctgReleaseDBCache(pCtg, dbCache); - tfree(*pTableMeta); + taosMemoryFreeClear(*pTableMeta); ctgError("stable suid in stbCache mis-match, expected suid:%"PRIx64 ",actual suid:%"PRIx64, tbMeta->suid, (*stbMeta)->suid); CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } int32_t metaSize = CTG_META_SIZE(*stbMeta); - *pTableMeta = realloc(*pTableMeta, metaSize); + *pTableMeta = taosMemoryRealloc(*pTableMeta, metaSize); if (NULL == *pTableMeta) { CTG_UNLOCK(CTG_READ, &dbCache->tbCache.stbLock); ctgReleaseDBCache(pCtg, dbCache); @@ -1161,7 +1161,7 @@ int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type) { size_t msgSize = sizeof(SCtgRentSlot) * mgmt->slotNum; - mgmt->slots = calloc(1, msgSize); + mgmt->slots = taosMemoryCalloc(1, msgSize); if (NULL == mgmt->slots) { qError("calloc %d failed", (int32_t)msgSize); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -1305,7 +1305,7 @@ int32_t ctgMetaRentGetImpl(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_ } size_t msize = metaNum * size; - *res = malloc(msize); + *res = taosMemoryMalloc(msize); if (NULL == *res) { qError("malloc %d failed", (int32_t)msize); CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); @@ -1631,7 +1631,7 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui } int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) { - *dst = malloc(sizeof(SDBVgInfo)); + *dst = taosMemoryMalloc(sizeof(SDBVgInfo)); if (NULL == *dst) { qError("malloc %d failed", (int32_t)sizeof(SDBVgInfo)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -1643,7 +1643,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) { (*dst)->vgHash = taosHashInit(hashSize, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); if (NULL == (*dst)->vgHash) { qError("taosHashInit %d failed", (int32_t)hashSize); - tfree(*dst); + taosMemoryFreeClear(*dst); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } @@ -1656,7 +1656,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) { qError("taosHashPut failed, hashSize:%d", (int32_t)hashSize); taosHashCancelIterate(src->vgHash, pIter); taosHashCleanup((*dst)->vgHash); - tfree(*dst); + taosMemoryFreeClear(*dst); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } @@ -1703,7 +1703,7 @@ int32_t ctgGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const _return: - tfree(*pInfo); + taosMemoryFreeClear(*pInfo); *pInfo = DbOut.dbVgroup; CTG_RET(code); @@ -1748,7 +1748,7 @@ int32_t ctgRefreshDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, c int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput) { - *pOutput = malloc(sizeof(STableMetaOutput)); + *pOutput = taosMemoryMalloc(sizeof(STableMetaOutput)); if (NULL == *pOutput) { qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -1758,10 +1758,10 @@ int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput) if (output->tbMeta) { int32_t metaSize = CTG_META_SIZE(output->tbMeta); - (*pOutput)->tbMeta = malloc(metaSize); + (*pOutput)->tbMeta = taosMemoryMalloc(metaSize); if (NULL == (*pOutput)->tbMeta) { qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); - tfree(*pOutput); + taosMemoryFreeClear(*pOutput); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } @@ -1786,7 +1786,7 @@ int32_t ctgRefreshTblMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, } STableMetaOutput moutput = {0}; - STableMetaOutput *output = calloc(1, sizeof(STableMetaOutput)); + STableMetaOutput *output = taosMemoryCalloc(1, sizeof(STableMetaOutput)); if (NULL == output) { ctgError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -1814,7 +1814,7 @@ int32_t ctgRefreshTblMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, if (CTG_IS_META_TABLE(output->metaType) && TSDB_SUPER_TABLE == output->tbMeta->tableType) { ctgDebug("will continue to refresh tbmeta since got stb, tbName:%s", tNameGetTableName(pTableName)); - tfree(output->tbMeta); + taosMemoryFreeClear(output->tbMeta); CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCtg, pTrans, pMgmtEps, output->dbFName, output->tbName, output)); } else if (CTG_IS_META_BOTH(output->metaType)) { @@ -1830,11 +1830,11 @@ int32_t ctgRefreshTblMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, SET_META_TYPE_NULL(output->metaType); } - tfree(output->tbMeta); + taosMemoryFreeClear(output->tbMeta); output->tbMeta = moutput.tbMeta; moutput.tbMeta = NULL; } else { - tfree(output->tbMeta); + taosMemoryFreeClear(output->tbMeta); SET_META_TYPE_CTABLE(output->metaType); } @@ -1862,8 +1862,8 @@ int32_t ctgRefreshTblMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, _return: - tfree(output->tbMeta); - tfree(output); + taosMemoryFreeClear(output->tbMeta); + taosMemoryFreeClear(output); CTG_RET(code); } @@ -1895,7 +1895,7 @@ int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons tbType = (*pTableMeta)->tableType; suid = (*pTableMeta)->suid; - tfree(*pTableMeta); + taosMemoryFreeClear(*pTableMeta); } if (CTG_FLAG_IS_UNKNOWN_STB(flag)) { @@ -1920,7 +1920,7 @@ int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons if ((!CTG_IS_META_CTABLE(output->metaType)) || output->tbMeta) { ctgError("invalid metaType:%d", output->metaType); - tfree(output->tbMeta); + taosMemoryFreeClear(output->tbMeta); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } @@ -1957,7 +1957,7 @@ _return: } } - tfree(output); + taosMemoryFreeClear(output); if (*pTableMeta) { ctgDebug("tbmeta returned, tbName:%s, tbType:%d", pTableName->tname, (*pTableMeta)->tableType); @@ -1978,7 +1978,7 @@ int32_t ctgActUpdateVg(SCtgMetaAction *action) { _return: ctgFreeVgInfo(msg->dbInfo); - tfree(msg); + taosMemoryFreeClear(msg); CTG_RET(code); } @@ -2003,7 +2003,7 @@ int32_t ctgActRemoveDB(SCtgMetaAction *action) { _return: - tfree(msg); + taosMemoryFreeClear(msg); CTG_RET(code); } @@ -2045,11 +2045,11 @@ int32_t ctgActUpdateTbl(SCtgMetaAction *action) { _return: if (output) { - tfree(output->tbMeta); - tfree(output); + taosMemoryFreeClear(output->tbMeta); + taosMemoryFreeClear(output); } - tfree(msg); + taosMemoryFreeClear(msg); CTG_RET(code); } @@ -2092,7 +2092,7 @@ int32_t ctgActRemoveStb(SCtgMetaAction *action) { _return: - tfree(msg); + taosMemoryFreeClear(msg); CTG_RET(code); } @@ -2125,7 +2125,7 @@ int32_t ctgActRemoveTbl(SCtgMetaAction *action) { _return: - tfree(msg); + taosMemoryFreeClear(msg); CTG_RET(code); } @@ -2248,11 +2248,11 @@ _return: ctgReleaseDBCache(pCtg, dbCache); } - tfree(tbMeta); + taosMemoryFreeClear(tbMeta); if (vgInfo) { taosHashCleanup(vgInfo->vgHash); - tfree(vgInfo); + taosMemoryFreeClear(vgInfo); } if (vgList) { @@ -2308,7 +2308,7 @@ int32_t catalogInit(SCatalogCfg *cfg) { tsem_init(&gCtgMgmt.queue.reqSem, 0, 0); tsem_init(&gCtgMgmt.queue.rspSem, 0, 0); - gCtgMgmt.queue.head = calloc(1, sizeof(SCtgQNode)); + gCtgMgmt.queue.head = taosMemoryCalloc(1, sizeof(SCtgQNode)); if (NULL == gCtgMgmt.queue.head) { qError("calloc %d failed", (int32_t)sizeof(SCtgQNode)); CTG_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -2342,7 +2342,7 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) { return TSDB_CODE_SUCCESS; } - clusterCtg = calloc(1, sizeof(SCatalog)); + clusterCtg = taosMemoryCalloc(1, sizeof(SCatalog)); if (NULL == clusterCtg) { qError("calloc %d failed", (int32_t)sizeof(SCatalog)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); @@ -2483,7 +2483,7 @@ _return: if (vgInfo) { taosHashCleanup(vgInfo->vgHash); - tfree(vgInfo); + taosMemoryFreeClear(vgInfo); } CTG_API_LEAVE(code); @@ -2569,7 +2569,7 @@ int32_t catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName) { _return: - tfree(tblMeta); + taosMemoryFreeClear(tblMeta); CTG_API_LEAVE(code); } @@ -2620,7 +2620,7 @@ int32_t catalogUpdateSTableMeta(SCatalog* pCtg, STableMetaRsp *rspMsg) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } - STableMetaOutput *output = calloc(1, sizeof(STableMetaOutput)); + STableMetaOutput *output = taosMemoryCalloc(1, sizeof(STableMetaOutput)); if (NULL == output) { ctgError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); CTG_API_LEAVE(TSDB_CODE_CTG_MEM_ERROR); @@ -2643,8 +2643,8 @@ int32_t catalogUpdateSTableMeta(SCatalog* pCtg, STableMetaRsp *rspMsg) { _return: - tfree(output->tbMeta); - tfree(output); + taosMemoryFreeClear(output->tbMeta); + taosMemoryFreeClear(output); CTG_API_LEAVE(code); } @@ -2739,7 +2739,7 @@ _return: if (vgInfo) { taosHashCleanup(vgInfo->vgHash); - tfree(vgInfo); + taosMemoryFreeClear(vgInfo); } CTG_API_LEAVE(code); @@ -2777,7 +2777,7 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, if (NULL == taosArrayPush(pRsp->pTableMeta, &pTableMeta)) { ctgError("taosArrayPush failed, idx:%d", i); - tfree(pTableMeta); + taosMemoryFreeClear(pTableMeta); CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } } @@ -2795,7 +2795,7 @@ _return: int32_t aSize = taosArrayGetSize(pRsp->pTableMeta); for (int32_t i = 0; i < aSize; ++i) { STableMeta *pMeta = taosArrayGetP(pRsp->pTableMeta, i); - tfree(pMeta); + taosMemoryFreeClear(pMeta); } taosArrayDestroy(pRsp->pTableMeta); diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index aff2c2edcd..e62819b078 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -176,7 +176,7 @@ void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) { output->ctbMeta.uid = 3; output->ctbMeta.suid = 2; - output->tbMeta = (STableMeta *)calloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum)); + output->tbMeta = (STableMeta *)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum)); output->tbMeta->vgId = 9; output->tbMeta->tableType = TSDB_SUPER_TABLE; output->tbMeta->uid = 2; @@ -212,7 +212,7 @@ void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) { static int32_t vgVersion = ctgTestVgVersion + 1; int32_t vgNum = 0; SVgroupInfo vgInfo = {0}; - SDBVgInfo *dbVgroup = (SDBVgInfo *)calloc(1, sizeof(SDBVgInfo)); + SDBVgInfo *dbVgroup = (SDBVgInfo *)taosMemoryCalloc(1, sizeof(SDBVgInfo)); dbVgroup->vgVersion = vgVersion++; @@ -257,7 +257,7 @@ void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) { rspMsg->tuid = ctgTestSuid + 1; rspMsg->vgId = 1; - rspMsg->pSchemas = (SSchema *)calloc(rspMsg->numOfTags + rspMsg->numOfColumns, sizeof(SSchema)); + rspMsg->pSchemas = (SSchema *)taosMemoryCalloc(rspMsg->numOfTags + rspMsg->numOfColumns, sizeof(SSchema)); SSchema *s = NULL; s = &rspMsg->pSchemas[0]; @@ -335,7 +335,7 @@ void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg * metaRsp.suid = 0; metaRsp.tuid = ctgTestNormalTblUid++; metaRsp.vgId = 8; - metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); + metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); SSchema *s = NULL; s = &metaRsp.pSchemas[0]; @@ -381,7 +381,7 @@ void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg metaRsp.suid = 0x0000000000000002; metaRsp.tuid = 0x0000000000000003; metaRsp.vgId = 9; - metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); + metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); SSchema *s = NULL; s = &metaRsp.pSchemas[0]; @@ -428,7 +428,7 @@ void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg metaRsp.suid = ctgTestSuid; metaRsp.tuid = ctgTestSuid++; metaRsp.vgId = 0; - metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); + metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); SSchema *s = NULL; s = &metaRsp.pSchemas[0]; @@ -477,7 +477,7 @@ void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRp metaRsp.suid = ctgTestSuid + idx; metaRsp.tuid = ctgTestSuid + idx; metaRsp.vgId = 0; - metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); + metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); SSchema *s = NULL; s = &metaRsp.pSchemas[0]; @@ -798,7 +798,7 @@ void *ctgTestGetCtableMetaThread(void *param) { assert(0); } - tfree(tbMeta); + taosMemoryFreeClear(tbMeta); if (ctgTestEnableSleep) { taosUsleep(taosRand() % 5); @@ -824,10 +824,10 @@ void *ctgTestSetCtableMetaThread(void *param) { action.act = CTG_ACT_UPDATE_TBL; while (!ctgTestStop) { - output = (STableMetaOutput *)malloc(sizeof(STableMetaOutput)); + output = (STableMetaOutput *)taosMemoryMalloc(sizeof(STableMetaOutput)); ctgTestBuildCTableMetaOutput(output); - SCtgUpdateTblMsg *msg = (SCtgUpdateTblMsg *)malloc(sizeof(SCtgUpdateTblMsg)); + SCtgUpdateTblMsg *msg = (SCtgUpdateTblMsg *)taosMemoryMalloc(sizeof(SCtgUpdateTblMsg)); msg->pCtg = pCtg; msg->output = output; action.data = msg; @@ -933,7 +933,7 @@ TEST(tableMeta, normalTable) { if (dbNum) { printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId); - free(dbs); + taosMemoryFree(dbs); dbs = NULL; } else { printf("no expired db\n"); @@ -941,7 +941,7 @@ TEST(tableMeta, normalTable) { if (stbNum) { printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName); - free(stb); + taosMemoryFree(stb); stb = NULL; } else { printf("no expired stb\n"); @@ -1015,7 +1015,7 @@ TEST(tableMeta, childTableCase) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); strcpy(n.tname, ctgTestSTablename); code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); @@ -1042,7 +1042,7 @@ TEST(tableMeta, childTableCase) { if (dbNum) { printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId); - free(dbs); + taosMemoryFree(dbs); dbs = NULL; } else { printf("no expired db\n"); @@ -1050,7 +1050,7 @@ TEST(tableMeta, childTableCase) { if (stbNum) { printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName); - free(stb); + taosMemoryFree(stb); stb = NULL; } else { printf("no expired stb\n"); @@ -1164,7 +1164,7 @@ TEST(tableMeta, superTableCase) { if (dbNum) { printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId); - free(dbs); + taosMemoryFree(dbs); dbs = NULL; } else { printf("no expired db\n"); @@ -1173,7 +1173,7 @@ TEST(tableMeta, superTableCase) { if (stbNum) { printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName); - free(stb); + taosMemoryFree(stb); stb = NULL; } else { printf("no expired stb\n"); @@ -1307,14 +1307,14 @@ TEST(tableMeta, updateStbMeta) { } - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); STableMetaRsp rsp = {0}; ctgTestBuildSTableMetaRsp(&rsp); code = catalogUpdateSTableMeta(pCtg, &rsp); ASSERT_EQ(code, 0); - tfree(rsp.pSchemas); + taosMemoryFreeClear(rsp.pSchemas); while (true) { uint64_t n = 0; @@ -1345,7 +1345,7 @@ TEST(tableMeta, updateStbMeta) { ASSERT_EQ(tableMeta->tableInfo.precision, 1 + 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); catalogDestroy(); memset(&gCtgMgmt.stat, 0, sizeof(gCtgMgmt.stat)); @@ -1407,7 +1407,7 @@ TEST(refreshGetMeta, normal2normal) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); @@ -1424,7 +1424,7 @@ TEST(refreshGetMeta, normal2normal) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -1486,7 +1486,7 @@ TEST(refreshGetMeta, normal2notexist) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); @@ -1560,7 +1560,7 @@ TEST(refreshGetMeta, normal2child) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); @@ -1576,7 +1576,7 @@ TEST(refreshGetMeta, normal2child) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -1645,7 +1645,7 @@ TEST(refreshGetMeta, stable2child) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); @@ -1662,7 +1662,7 @@ TEST(refreshGetMeta, stable2child) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -1730,7 +1730,7 @@ TEST(refreshGetMeta, stable2stable) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); @@ -1748,7 +1748,7 @@ TEST(refreshGetMeta, stable2stable) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -1816,7 +1816,7 @@ TEST(refreshGetMeta, child2stable) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); while (2 != ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); @@ -1835,7 +1835,7 @@ TEST(refreshGetMeta, child2stable) { ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - tfree(tableMeta); + taosMemoryFreeClear(tableMeta); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -2275,7 +2275,7 @@ TEST(rentTest, allRent) { printf("%d - expired dbNum:%d\n", i, num); if (dbs) { printf("%d - expired dbId:%" PRId64 ", vgVersion:%d\n", i, dbs->dbId, dbs->vgVersion); - free(dbs); + taosMemoryFree(dbs); dbs = NULL; } @@ -2287,7 +2287,7 @@ TEST(rentTest, allRent) { printf("suid:%" PRId64 ", dbFName:%s, stbName:%s, sversion:%d, tversion:%d\n", stable[n].suid, stable[n].dbFName, stable[n].stbName, stable[n].sversion, stable[n].tversion); } - free(stable); + taosMemoryFree(stable); stable = NULL; } printf("*************************************************\n"); diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 1c2d9424d3..34894c235b 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -142,7 +142,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockDataGetSerialMetaSize(pInput->pData) + ceil(blockDataGetSerialRowSize(pInput->pData) * pInput->pData->info.rows); - pBuf->pData = malloc(pBuf->allocSize); + pBuf->pData = taosMemoryMalloc(pBuf->allocSize); if (pBuf->pData == NULL) { qError("SinkNode failed to malloc memory, size:%d, code:%d", pBuf->allocSize, TAOS_SYSTEM_ERROR(errno)); } @@ -215,7 +215,7 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) { memcpy(pOutput->pData, pEntry->data, pEntry->dataLen); pOutput->numOfRows = pEntry->numOfRows; pOutput->compressed = pEntry->compressed; - tfree(pDispatcher->nextOutput.pData); // todo persistent + taosMemoryFreeClear(pDispatcher->nextOutput.pData); // todo persistent pOutput->bufStatus = updateStatus(pDispatcher); taosThreadMutexLock(&pDispatcher->mutex); pOutput->queryEnd = pDispatcher->queryEnd; @@ -227,11 +227,11 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) { static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle; - tfree(pDispatcher->nextOutput.pData); + taosMemoryFreeClear(pDispatcher->nextOutput.pData); while (!taosQueueEmpty(pDispatcher->pDataBlocks)) { SDataDispatchBuf* pBuf = NULL; taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf); - tfree(pBuf->pData); + taosMemoryFreeClear(pBuf->pData); taosFreeQitem(pBuf); } taosCloseQueue(pDispatcher->pDataBlocks); @@ -239,7 +239,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { } int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle) { - SDataDispatchHandle* dispatcher = calloc(1, sizeof(SDataDispatchHandle)); + SDataDispatchHandle* dispatcher = taosMemoryCalloc(1, sizeof(SDataDispatchHandle)); if (NULL == dispatcher) { terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return TSDB_CODE_QRY_OUT_OF_MEMORY; diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index a04a10ef95..f0cffafca2 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -58,8 +58,8 @@ int32_t initResultRowInfo(SResultRowInfo *pResultRowInfo, int32_t size) { pResultRowInfo->curPos = -1; pResultRowInfo->capacity = size; - pResultRowInfo->pResult = calloc(pResultRowInfo->capacity, POINTER_BYTES); - pResultRowInfo->pPosition = calloc(pResultRowInfo->capacity, sizeof(SResultRowPosition)); + pResultRowInfo->pResult = taosMemoryCalloc(pResultRowInfo->capacity, POINTER_BYTES); + pResultRowInfo->pPosition = taosMemoryCalloc(pResultRowInfo->capacity, sizeof(SResultRowPosition)); if (pResultRowInfo->pResult == NULL || pResultRowInfo->pPosition == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -79,11 +79,11 @@ void cleanupResultRowInfo(SResultRowInfo *pResultRowInfo) { for(int32_t i = 0; i < pResultRowInfo->size; ++i) { if (pResultRowInfo->pResult[i]) { - tfree(pResultRowInfo->pResult[i]->key); + taosMemoryFreeClear(pResultRowInfo->pResult[i]->key); } } - tfree(pResultRowInfo->pResult); + taosMemoryFreeClear(pResultRowInfo->pResult); } void resetResultRowInfo(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo) { @@ -163,7 +163,7 @@ void clearResultRow(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow) { pResultRow->offset = -1; pResultRow->closed = false; - tfree(pResultRow->key); + taosMemoryFreeClear(pResultRow->key); pResultRow->win = TSWINDOW_INITIALIZER; } @@ -190,7 +190,7 @@ SResultRow* getNewResultRow(SResultRowPool* p) { void* ptr = NULL; if (p->position.pos == 0) { - ptr = calloc(1, p->blockSize); + ptr = taosMemoryCalloc(1, p->blockSize); taosArrayPush(p->pData, &ptr); } else { @@ -403,8 +403,8 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv pGroupResInfo->pRows = taosArrayInit(100, POINTER_BYTES); } - posList = calloc(size, sizeof(int32_t)); - pTableQueryInfoList = malloc(POINTER_BYTES * size); + posList = taosMemoryCalloc(size, sizeof(int32_t)); + pTableQueryInfoList = taosMemoryMalloc(POINTER_BYTES * size); if (pTableQueryInfoList == NULL || posList == NULL || pGroupResInfo->pRows == NULL || pGroupResInfo->pRows == NULL) { // qError("QInfo:%"PRIu64" failed alloc memory", GET_TASKID(pRuntimeEnv)); @@ -483,9 +483,9 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv // pGroupResInfo->currentGroup, endt - startt); _end: - tfree(pTableQueryInfoList); - tfree(posList); - tfree(pTree); + taosMemoryFreeClear(pTableQueryInfoList); + taosMemoryFreeClear(posList); + taosMemoryFreeClear(pTree); return code; } @@ -529,7 +529,7 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRun // // // compress extra bytes // size_t x = taosArrayGetSize(pDist->dataBlockInfos) * pDist->dataBlockInfos->elemSize; -// char* tmp = malloc(x + 2); +// char* tmp = taosMemoryMalloc(x + 2); // // bool comp = false; // int32_t len = tsCompressString(p, (int32_t)x, 1, tmp, (int32_t)x, ONE_STAGE_COMP, NULL, 0); @@ -547,7 +547,7 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRun // } else { // tbufWriteBinary(bw, p, len); // } -// tfree(tmp); +// taosMemoryFreeClear(tmp); //} //void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDist* pDist) { @@ -570,7 +570,7 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRun // // char* outputBuf = NULL; // if (comp) { -// outputBuf = malloc(originalLen); +// outputBuf = taosMemoryMalloc(originalLen); // // size_t actualLen = compLen; // const char* compStr = tbufReadBinary(&br, &actualLen); @@ -584,7 +584,7 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRun // // pDist->dataBlockInfos = taosArrayFromList(outputBuf, (uint32_t)numSteps, sizeof(SFileBlockInfo)); // if (comp) { -// tfree(outputBuf); +// taosMemoryFreeClear(outputBuf); // } //} diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index cea9b3ce11..fc0535358b 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -73,7 +73,7 @@ static UNUSED_FUNC void *u_malloc (size_t __size) { if (v % 1000 <= 0) { return NULL; } else { - return malloc(__size); + return taosMemoryMalloc(__size); } } @@ -82,7 +82,7 @@ static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) { if (v % 1000 <= 0) { return NULL; } else { - return calloc(num, __size); + return taosMemoryCalloc(num, __size); } } @@ -91,7 +91,7 @@ static UNUSED_FUNC void* u_realloc(void* p, size_t __size) { if (v % 5 <= 1) { return NULL; } else { - return realloc(p, __size); + return taosMemoryRealloc(p, __size); } } @@ -320,7 +320,7 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, STaskRuntimeEn SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numOfRows) { const static int32_t minSize = 8; - SSDataBlock *res = calloc(1, sizeof(SSDataBlock)); + SSDataBlock *res = taosMemoryCalloc(1, sizeof(SSDataBlock)); res->info.numOfCols = numOfOutput; res->pDataBlock = taosArrayInit(numOfOutput, sizeof(SColumnInfoData)); for (int32_t i = 0; i < numOfOutput; ++i) { @@ -330,7 +330,7 @@ SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numO idata.info.colId = pExpr[i].base.resSchema.colId; int32_t size = TMAX(idata.info.bytes * numOfRows, minSize); - idata.pData = calloc(1, size); // at least to hold a pointer on x64 platform + idata.pData = taosMemoryCalloc(1, size); // at least to hold a pointer on x64 platform taosArrayPush(res->pDataBlock, &idata); } @@ -340,7 +340,7 @@ SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numO SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { int32_t numOfCols = LIST_LENGTH(pNode->pSlots); - SSDataBlock* pBlock = calloc(1, sizeof(SSDataBlock)); + SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); pBlock->info.numOfCols = numOfCols; pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); @@ -423,12 +423,12 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env) newCapacity += 4; } - char *t = realloc(pResultRowInfo->pResult, (size_t)(newCapacity * POINTER_BYTES)); + char *t = taosMemoryRealloc(pResultRowInfo->pResult, (size_t)(newCapacity * POINTER_BYTES)); if (t == NULL) { longjmp(env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - pResultRowInfo->pPosition = realloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition)); + pResultRowInfo->pPosition = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition)); pResultRowInfo->pResult = (SResultRow **)t; int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity; @@ -1857,7 +1857,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { if (IS_VAR_DATA_TYPE(type)) { if (pResultRow->key == NULL) { - pResultRow->key = malloc(varDataTLen(pData)); + pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); varDataCopy(pResultRow->key, pData); } else { assert(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); @@ -1976,7 +1976,7 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx *pCtx, int32_t numOfOutput) { int16_t tagLen = 0; SqlFunctionCtx* p = NULL; - SqlFunctionCtx** pTagCtx = calloc(numOfOutput, POINTER_BYTES); + SqlFunctionCtx** pTagCtx = taosMemoryCalloc(numOfOutput, POINTER_BYTES); if (pTagCtx == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -2002,7 +2002,7 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx *pCtx, int32_t numOfOutput) { p->subsidiaryRes.numOfCols = num; p->subsidiaryRes.bufLen = tagLen; } else { - tfree(pTagCtx); + taosMemoryFreeClear(pTagCtx); } return TSDB_CODE_SUCCESS; @@ -2012,14 +2012,14 @@ static SqlFunctionCtx* createSqlFunctionCtx(STaskRuntimeEnv* pRuntimeEnv, SExprI int32_t** rowCellInfoOffset) { STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)calloc(numOfOutput, sizeof(SqlFunctionCtx)); + SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx)); if (pFuncCtx == NULL) { return NULL; } - *rowCellInfoOffset = calloc(numOfOutput, sizeof(int32_t)); + *rowCellInfoOffset = taosMemoryCalloc(numOfOutput, sizeof(int32_t)); if (*rowCellInfoOffset == 0) { - tfree(pFuncCtx); + taosMemoryFreeClear(pFuncCtx); return NULL; } @@ -2110,14 +2110,14 @@ static SqlFunctionCtx* createSqlFunctionCtx(STaskRuntimeEnv* pRuntimeEnv, SExprI } static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) { - SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)calloc(numOfOutput, sizeof(SqlFunctionCtx)); + SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx)); if (pFuncCtx == NULL) { return NULL; } - *rowCellInfoOffset = calloc(numOfOutput, sizeof(int32_t)); + *rowCellInfoOffset = taosMemoryCalloc(numOfOutput, sizeof(int32_t)); if (*rowCellInfoOffset == 0) { - tfree(pFuncCtx); + taosMemoryFreeClear(pFuncCtx); return NULL; } @@ -2139,8 +2139,8 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num } pCtx->input.numOfInputCols = pFunct->numOfParams; - pCtx->input.pData = calloc(pFunct->numOfParams, POINTER_BYTES); - pCtx->input.pColumnDataAgg = calloc(pFunct->numOfParams, POINTER_BYTES); + pCtx->input.pData = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES); + pCtx->input.pColumnDataAgg = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES); pCtx->ptsOutputBuf = NULL; pCtx->resDataInfo.bytes = pFunct->resSchema.bytes; @@ -2216,10 +2216,10 @@ static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput) { } taosVariantDestroy(&pCtx[i].tag); - tfree(pCtx[i].subsidiaryRes.pCtx); + taosMemoryFreeClear(pCtx[i].subsidiaryRes.pCtx); } - tfree(pCtx); + taosMemoryFreeClear(pCtx); return NULL; } @@ -2232,12 +2232,12 @@ static int32_t setupQueryRuntimeEnv(STaskRuntimeEnv *pRuntimeEnv, int32_t numOfT pRuntimeEnv->pResultRowHashTable = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pRuntimeEnv->pResultRowListSet = taosHashInit(numOfTables * 10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - pRuntimeEnv->keyBuf = malloc(pQueryAttr->maxTableColumnWidth + sizeof(int64_t) + POINTER_BYTES); + pRuntimeEnv->keyBuf = taosMemoryMalloc(pQueryAttr->maxTableColumnWidth + sizeof(int64_t) + POINTER_BYTES); // pRuntimeEnv->pool = initResultRowPool(getResultRowSize(pRuntimeEnv)); pRuntimeEnv->pResultRowArrayList = taosArrayInit(numOfTables, sizeof(SResultRowCell)); - pRuntimeEnv->prevRow = malloc(POINTER_BYTES * pQueryAttr->numOfCols + pQueryAttr->srcRowSize); - pRuntimeEnv->tagVal = malloc(pQueryAttr->tagLen); + pRuntimeEnv->prevRow = taosMemoryMalloc(POINTER_BYTES * pQueryAttr->numOfCols + pQueryAttr->srcRowSize); + pRuntimeEnv->tagVal = taosMemoryMalloc(pQueryAttr->tagLen); // NOTE: pTableCheckInfo need to update the query time range and the lastKey info pRuntimeEnv->pTableRetrieveTsMap = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); @@ -2269,10 +2269,10 @@ static int32_t setupQueryRuntimeEnv(STaskRuntimeEnv *pRuntimeEnv, int32_t numOfT _clean: //destroyScalarFuncSupport(pRuntimeEnv->scalarSup, pRuntimeEnv->pQueryAttr->numOfOutput); - tfree(pRuntimeEnv->pResultRowHashTable); - tfree(pRuntimeEnv->keyBuf); - tfree(pRuntimeEnv->prevRow); - tfree(pRuntimeEnv->tagVal); + taosMemoryFreeClear(pRuntimeEnv->pResultRowHashTable); + taosMemoryFreeClear(pRuntimeEnv->keyBuf); + taosMemoryFreeClear(pRuntimeEnv->prevRow); + taosMemoryFreeClear(pRuntimeEnv->tagVal); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -2806,7 +2806,7 @@ void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo SSDataBlock* pBlock, bool ascQuery) { int32_t numOfRows = pBlock->info.rows; - int8_t *p = calloc(numOfRows, sizeof(int8_t)); + int8_t *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); bool all = true; #if 0 if (pRuntimeEnv->pTsBuf != NULL) { @@ -2842,7 +2842,7 @@ void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo doCompactSDataBlock(pBlock, numOfRows, p); } - tfree(p); + taosMemoryFreeClear(p); } void filterColRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock, bool ascQuery) { @@ -2853,7 +2853,7 @@ void filterColRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock, if (pRuntimeEnv->pTsBuf != NULL) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); - p = calloc(numOfRows, sizeof(int8_t)); + p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); TSKEY* k = (TSKEY*) pColInfoData->pData; for (int32_t i = 0; i < numOfRows; ++i) { @@ -2889,7 +2889,7 @@ void filterColRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock, } } - tfree(p); + taosMemoryFreeClear(p); } static SColumnInfo* doGetTagColumnInfoById(SColumnInfo* pTagColList, int32_t numOfTags, int16_t colId); @@ -3410,7 +3410,7 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf for(int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { SColumnInfoData *pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); - char* p = realloc(pColInfo->pData, newSize * pColInfo->info.bytes); + char* p = taosMemoryRealloc(pColInfo->pData, newSize * pColInfo->info.bytes); if (p != NULL) { pColInfo->pData = p; @@ -3598,7 +3598,7 @@ STableQueryInfo *createTableQueryInfo(void* buf, bool groupbyColumn, STimeWindow } STableQueryInfo* createTmpTableQueryInfo(STimeWindow win) { - STableQueryInfo* pTableQueryInfo = calloc(1, sizeof(STableQueryInfo)); + STableQueryInfo* pTableQueryInfo = taosMemoryCalloc(1, sizeof(STableQueryInfo)); // pTableQueryInfo->win = win; pTableQueryInfo->lastKey = win.skey; @@ -3607,7 +3607,7 @@ STableQueryInfo* createTmpTableQueryInfo(STimeWindow win) { int32_t initialSize = 16; int32_t code = initResultRowInfo(&pTableQueryInfo->resInfo, initialSize); if (code != TSDB_CODE_SUCCESS) { - tfree(pTableQueryInfo); + taosMemoryFreeClear(pTableQueryInfo); return NULL; } @@ -4425,7 +4425,7 @@ int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t assert(p->numOfDownstream == 0); } - p->pDownstream = calloc(1, num * POINTER_BYTES); + p->pDownstream = taosMemoryCalloc(1, num * POINTER_BYTES); if (p->pDownstream == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -4780,7 +4780,7 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo *pOperator, bool* newgroup) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0); int32_t len = (int32_t) tbufTell(&bw); - pColInfo->pData = malloc(len + sizeof(int32_t)); + pColInfo->pData = taosMemoryMalloc(len + sizeof(int32_t)); *(int32_t*) pColInfo->pData = len; memcpy(pColInfo->pData + sizeof(int32_t), tbufGetData(&bw, false), len); @@ -4861,8 +4861,8 @@ int32_t loadRemoteDataCallback(void* param, const SDataBuf* pMsg, int32_t code) static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { assert(pMsgBody != NULL); - tfree(pMsgBody->msgInfo.pData); - tfree(pMsgBody); + taosMemoryFreeClear(pMsgBody->msgInfo.pData); + taosMemoryFreeClear(pMsgBody); } void qProcessFetchRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { @@ -4872,7 +4872,7 @@ void qProcessFetchRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { SDataBuf buf = {.len = pMsg->contLen, .pData = NULL}; if (pMsg->contLen > 0) { - buf.pData = calloc(1, pMsg->contLen); + buf.pData = taosMemoryCalloc(1, pMsg->contLen); if (buf.pData == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; pMsg->code = TSDB_CODE_OUT_OF_MEMORY; @@ -4889,7 +4889,7 @@ void qProcessFetchRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { static int32_t doSendFetchDataRequest(SExchangeInfo *pExchangeInfo, SExecTaskInfo *pTaskInfo, int32_t sourceIndex) { size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); - SResFetchReq* pMsg = calloc(1, sizeof(SResFetchReq)); + SResFetchReq* pMsg = taosMemoryCalloc(1, sizeof(SResFetchReq)); if (NULL == pMsg) { pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return pTaskInfo->code; @@ -4907,9 +4907,9 @@ static int32_t doSendFetchDataRequest(SExchangeInfo *pExchangeInfo, SExecTaskInf pMsg->queryId = htobe64(pTaskInfo->id.queryId); // send the fetch remote task result reques - SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); + SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == pMsgSendInfo) { - tfree(pMsg); + taosMemoryFreeClear(pMsg); qError("%s prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo)); pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return pTaskInfo->code; @@ -4947,7 +4947,7 @@ static int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* memcpy(pColInfoData->varmeta.offset, pStart, sizeof(int32_t)*numOfRows); pStart += sizeof(int32_t)*numOfRows; - pColInfoData->pData = malloc(colLen[i]); + pColInfoData->pData = taosMemoryMalloc(colLen[i]); } else { memcpy(pColInfoData->nullbitmap, pStart, BitmapLen(numOfRows)); pStart += BitmapLen(numOfRows); @@ -5237,8 +5237,8 @@ static SSDataBlock* doLoadRemoteData(SOperatorInfo *pOperator, bool* newgroup) { #if 0 _error: - tfree(pMsg); - tfree(pMsgSendInfo); + taosMemoryFreeClear(pMsg); + taosMemoryFreeClear(pMsgSendInfo); terrno = pTaskInfo->code; return NULL; @@ -5268,12 +5268,12 @@ static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo) { } SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) { - SExchangeInfo* pInfo = calloc(1, sizeof(SExchangeInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SExchangeInfo* pInfo = taosMemoryCalloc(1, sizeof(SExchangeInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } @@ -5342,14 +5342,14 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock destroyExchangeOperatorInfo(pInfo, numOfSources); } - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; return NULL; } SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { - SSDataBlock* pResBlock = calloc(1, sizeof(SSDataBlock)); + SSDataBlock* pResBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); if (pResBlock == NULL) { return NULL; } @@ -5377,11 +5377,11 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo) { assert(repeatTime > 0); - STableScanInfo* pInfo = calloc(1, sizeof(STableScanInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; @@ -5406,7 +5406,7 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, } SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv) { - STableScanInfo* pInfo = calloc(1, sizeof(STableScanInfo)); + STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); pInfo->pTsdbReadHandle = pTsdbReadHandle; pInfo->times = 1; @@ -5416,7 +5416,7 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntim pInfo->prevGroupId = -1; pRuntimeEnv->enableGroupData = true; - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "TableSeqScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN; pOperator->blockingOptr = false; @@ -5430,7 +5430,7 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntim } SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv) { - STableScanInfo* pInfo = calloc(1, sizeof(STableScanInfo)); + STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); pInfo->pTsdbReadHandle = pTsdbReadHandle; pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); @@ -5441,7 +5441,7 @@ SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRunt infoData.info.colId = 0; taosArrayPush(pInfo->block.pDataBlock, &infoData); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "TableBlockInfoScanOperator"; // pOperator->operatorType = OP_TableBlockInfoScan; pOperator->blockingOptr = false; @@ -5454,11 +5454,11 @@ SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRunt } SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { - SStreamBlockScanInfo* pInfo = calloc(1, sizeof(SStreamBlockScanInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } @@ -5467,8 +5467,8 @@ SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SSDataBlock* tqReadHandleSetColIdList((STqReadHandle* )streamReadHandle, pColList); int32_t code = tqReadHandleSetTbUidList(streamReadHandle, pTableIdList); if (code != 0) { - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); return NULL; } @@ -5602,11 +5602,11 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { strncpy(pInfo->req.tb, tNameGetTableName(&pInfo->name), tListLen(pInfo->req.tb)); int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &pInfo->req); - char* buf1 = calloc(1, contLen); + char* buf1 = taosMemoryCalloc(1, contLen); tSerializeSRetrieveTableReq(buf1, contLen, &pInfo->req); // send the fetch remote task result reques - SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); + SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == pMsgSendInfo) { qError("%s prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo)); pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; @@ -5645,11 +5645,11 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName, SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo) { - SSysTableScanInfo* pInfo = calloc(1, sizeof(SSysTableScanInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SSysTableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SSysTableScanInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } @@ -5832,7 +5832,7 @@ static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) { SSLimitOperatorInfo *pInfo = (SSLimitOperatorInfo*) param; taosArrayDestroy(pInfo->orderColumnList); pInfo->pRes = blockDataDestroy(pInfo->pRes); - tfree(pInfo->prevRow); + taosMemoryFreeClear(pInfo->prevRow); } static void assignExprInfo(SExprInfo* dst, const SExprInfo* src) { @@ -5841,7 +5841,7 @@ static void assignExprInfo(SExprInfo* dst, const SExprInfo* src) { *dst = *src; dst->pExpr = exprdup(src->pExpr); - dst->base.pParam = calloc(src->base.numOfParams, sizeof(SColumn)); + dst->base.pParam = taosMemoryCalloc(src->base.numOfParams, sizeof(SColumn)); memcpy(dst->base.pParam, src->base.pParam, sizeof(SColumn) * src->base.numOfParams); // memset(dst->base.param, 0, sizeof(SVariant) * tListLen(dst->base.param)); @@ -5853,7 +5853,7 @@ static void assignExprInfo(SExprInfo* dst, const SExprInfo* src) { static SExprInfo* exprArrayDup(SArray* pExprList) { size_t numOfOutput = taosArrayGetSize(pExprList); - SExprInfo* p = calloc(numOfOutput, sizeof(SExprInfo)); + SExprInfo* p = taosMemoryCalloc(numOfOutput, sizeof(SExprInfo)); for (int32_t i = 0; i < numOfOutput; ++i) { SExprInfo* pExpr = taosArrayGetP(pExprList, i); assignExprInfo(&p[i], pExpr); @@ -6087,11 +6087,11 @@ static SSDataBlock* doSortedMerge(SOperatorInfo *pOperator, bool* newgroup) { pInfo->pSortHandle = tsortCreateSortHandle(pInfo->orderInfo, pInfo->nullFirst, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, p, pInfo->binfo.pRes->info.numOfCols, "GET_TASKID(pTaskInfo)"); - tfree(p); + taosMemoryFreeClear(p); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); for(int32_t i = 0; i < pOperator->numOfDownstream; ++i) { - SGenericSource* ps = calloc(1, sizeof(SGenericSource)); + SGenericSource* ps = taosMemoryCalloc(1, sizeof(SGenericSource)); ps->param = pOperator->pDownstream[i]; tsortAddSource(pInfo->pSortHandle, ps); } @@ -6157,7 +6157,7 @@ static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGr ASSERT(taosArrayGetSize(pGroupInfo) == taosArrayGetSize(plist)); - pInfo->groupVal = calloc(1, (POINTER_BYTES * numOfGroupCol + len)); + pInfo->groupVal = taosMemoryCalloc(1, (POINTER_BYTES * numOfGroupCol + len)); if (pInfo->groupVal == NULL) { taosArrayDestroy(plist); return TSDB_CODE_OUT_OF_MEMORY; @@ -6177,8 +6177,8 @@ static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGr } SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo) { - SSortedMergeOperatorInfo* pInfo = calloc(1, sizeof(SSortedMergeOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SSortedMergeOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortedMergeOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -6233,8 +6233,8 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t destroySortedMergeOperatorInfo(pInfo, num); } - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } @@ -6255,10 +6255,10 @@ static SSDataBlock* doSort(SOperatorInfo *pOperator, bool* newgroup) { pInfo->pSortHandle = tsortCreateSortHandle(pInfo->orderInfo, pInfo->nullFirst, SORT_SINGLESOURCE_SORT, pInfo->bufPageSize, numOfBufPage, p, pInfo->pDataBlock->info.numOfCols, "GET_TASKID(pTaskInfo)"); - tfree(p); + taosMemoryFreeClear(p); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); - SGenericSource* ps = calloc(1, sizeof(SGenericSource)); + SGenericSource* ps = taosMemoryCalloc(1, sizeof(SGenericSource)); ps->param = pOperator; tsortAddSource(pInfo->pSortHandle, ps); @@ -6273,11 +6273,11 @@ static SSDataBlock* doSort(SOperatorInfo *pOperator, bool* newgroup) { } SOperatorInfo *createOrderOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SArray* pOrderVal, SExecTaskInfo* pTaskInfo) { - SOrderOperatorInfo* pInfo = calloc(1, sizeof(SOrderOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOrderOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SOrderOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } @@ -6296,9 +6296,9 @@ SOperatorInfo *createOrderOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx } if (pInfo->orderInfo == NULL || pInfo->pDataBlock == NULL) { - tfree(pOperator); + taosMemoryFreeClear(pOperator); destroyOrderOperatorInfo(pInfo, numOfCols); - tfree(pInfo); + taosMemoryFreeClear(pInfo); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; @@ -6386,7 +6386,7 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t int32_t size = taosHashGetSize(pSup->pResultRowHashTable); size_t keyLen = POINTER_BYTES; // estimate the key length int32_t totalSize = sizeof(int32_t) + size * (sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize); - *result = calloc(1, totalSize); + *result = taosMemoryCalloc(1, totalSize); if(*result == NULL){ terrno = TSDB_CODE_OUT_OF_MEMORY; return; @@ -6401,10 +6401,10 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t // recalculate the result size int32_t realTotalSize = offset + sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize; if (realTotalSize > totalSize){ - char *tmp = realloc(*result, realTotalSize); + char *tmp = taosMemoryRealloc(*result, realTotalSize); if (tmp == NULL){ terrno = TSDB_CODE_OUT_OF_MEMORY; - free(*result); + taosMemoryFree(*result); *result = NULL; return; }else{ @@ -6960,7 +6960,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI TSKEY* tsList = (TSKEY*)pTsColInfoData->pData; if (IS_REPEAT_SCAN(pRuntimeEnv) && !pInfo->reptScan) { pInfo->reptScan = true; - tfree(pInfo->prevData); + taosMemoryFreeClear(pInfo->prevData); } pInfo->numOfRows = 0; @@ -6970,7 +6970,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI continue; } if (pInfo->prevData == NULL) { - pInfo->prevData = malloc(bytes); + pInfo->prevData = taosMemoryMalloc(bytes); memcpy(pInfo->prevData, val, bytes); pInfo->numOfRows = 1; pInfo->curWindow.skey = tsList[j]; @@ -7304,19 +7304,19 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { destroyOperatorInfo(pOperator->pDownstream[i]); } - tfree(pOperator->pDownstream); + taosMemoryFreeClear(pOperator->pDownstream); pOperator->numOfDownstream = 0; } - tfree(pOperator->info); - tfree(pOperator); + taosMemoryFreeClear(pOperator->info); + taosMemoryFreeClear(pOperator); } int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx *pCtx, int32_t numOfOutput, const char* pKey) { _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput); - pAggSup->keyBuf = calloc(1, sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES); + pAggSup->keyBuf = taosMemoryCalloc(1, sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES); pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK); pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK); pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell)); @@ -7335,7 +7335,7 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx *pCtx, int32_t n } static void cleanupAggSup(SAggSupporter* pAggSup) { - tfree(pAggSup->keyBuf); + taosMemoryFreeClear(pAggSup->keyBuf); taosHashCleanup(pAggSup->pResultRowHashTable); taosHashCleanup(pAggSup->pResultRowListSet); taosArrayDestroy(pAggSup->pResultRowArrayList); @@ -7352,7 +7352,7 @@ static int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, S } static STableQueryInfo* initTableQueryInfo(const STableGroupInfo* pTableGroupInfo) { - STableQueryInfo* pTableQueryInfo = calloc(pTableGroupInfo->numOfTables, sizeof(STableQueryInfo)); + STableQueryInfo* pTableQueryInfo = taosMemoryCalloc(pTableGroupInfo->numOfTables, sizeof(STableQueryInfo)); if (pTableQueryInfo == NULL) { return NULL; } @@ -7377,8 +7377,8 @@ static STableQueryInfo* initTableQueryInfo(const STableGroupInfo* pTableGroupInf SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { - SAggOperatorInfo* pInfo = calloc(1, sizeof(SAggOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7416,8 +7416,8 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* return pOperator; _error: destroyAggOperatorInfo(pInfo, numOfCols); - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -7426,7 +7426,7 @@ static void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput) { assert(pInfo != NULL); destroySqlFunctionCtx(pInfo->pCtx, numOfOutput); - tfree(pInfo->rowCellInfoOffset); + taosMemoryFreeClear(pInfo->rowCellInfoOffset); cleanupResultRowInfo(&pInfo->resultRowInfo); pInfo->pRes = blockDataDestroy(pInfo->pRes); @@ -7440,7 +7440,7 @@ void destroyBasicOperatorInfo(void* param, int32_t numOfOutput) { void destroyStateWindowOperatorInfo(void* param, int32_t numOfOutput) { SStateWindowOperatorInfo* pInfo = (SStateWindowOperatorInfo*) param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); - tfree(pInfo->prevData); + taosMemoryFreeClear(pInfo->prevData); } void destroyAggOperatorInfo(void* param, int32_t numOfOutput) { @@ -7463,13 +7463,13 @@ void destroySFillOperatorInfo(void* param, int32_t numOfOutput) { SFillOperatorInfo* pInfo = (SFillOperatorInfo*) param; pInfo->pFillInfo = taosDestroyFillInfo(pInfo->pFillInfo); pInfo->pRes = blockDataDestroy(pInfo->pRes); - tfree(pInfo->p); + taosMemoryFreeClear(pInfo->p); } void destroyGroupbyOperatorInfo(void* param, int32_t numOfOutput) { SGroupbyOperatorInfo* pInfo = (SGroupbyOperatorInfo*) param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); - tfree(pInfo->keyBuf); + taosMemoryFreeClear(pInfo->keyBuf); taosArrayDestroy(pInfo->pGroupCols); taosArrayDestroy(pInfo->pGroupColVals); } @@ -7499,7 +7499,7 @@ static void destroyConditionOperatorInfo(void* param, int32_t numOfOutput) { static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) { SDistinctOperatorInfo* pInfo = (SDistinctOperatorInfo*) param; taosHashCleanup(pInfo->pSet); - tfree(pInfo->buf); + taosMemoryFreeClear(pInfo->buf); taosArrayDestroy(pInfo->pDistinctDataInfo); pInfo->pRes = blockDataDestroy(pInfo->pRes); } @@ -7526,7 +7526,7 @@ void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) { } SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { - SAggOperatorInfo* pInfo = calloc(1, sizeof(SAggOperatorInfo)); + SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); int32_t numOfRows = 1; int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); @@ -7538,7 +7538,7 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprI size_t tableGroup = taosArrayGetSize(pTableGroupInfo->pGroupList); initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)tableGroup); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "MultiTableAggregate"; // pOperator->operatorType = OP_MultiTableAggregate; pOperator->blockingOptr = true; @@ -7562,8 +7562,8 @@ _error: } SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { - SProjectOperatorInfo* pInfo = calloc(1, sizeof(SProjectOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SProjectOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SProjectOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7603,7 +7603,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int32_t* numOfFilterCols) { #if 0 - SColumnInfo* pCols = calloc(numOfOutput, sizeof(SColumnInfo)); + SColumnInfo* pCols = taosMemoryCalloc(numOfOutput, sizeof(SColumnInfo)); int32_t numOfFilter = 0; for(int32_t i = 0; i < numOfOutput; ++i) { @@ -7617,7 +7617,7 @@ SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int3 pCols[i].flist.numOfFilters = pExpr[i].base.flist.numOfFilters; if (pCols[i].flist.numOfFilters != 0) { - pCols[i].flist.filterInfo = calloc(pCols[i].flist.numOfFilters, sizeof(SColumnFilterInfo)); + pCols[i].flist.filterInfo = taosMemoryCalloc(pCols[i].flist.numOfFilters, sizeof(SColumnFilterInfo)); memcpy(pCols[i].flist.filterInfo, pExpr[i].base.flist.filterInfo, pCols[i].flist.numOfFilters * sizeof(SColumnFilterInfo)); } else { // avoid runtime error @@ -7635,8 +7635,8 @@ SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int3 } SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, SLimit* pLimit, SExecTaskInfo* pTaskInfo) { - SLimitOperatorInfo* pInfo = calloc(1, sizeof(SLimitOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SLimitOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SLimitOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7656,16 +7656,16 @@ SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, SLimit* pLimit return pOperator; _error: - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) { - STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7708,20 +7708,20 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* _error: destroyIntervalOperatorInfo(pInfo, numOfCols); - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; } SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); + STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "AllTimeIntervalAggOperator"; // pOperator->operatorType = OP_AllTimeWindow; @@ -7739,14 +7739,14 @@ SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, S } SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { - SStateWindowOperatorInfo* pInfo = calloc(1, sizeof(SStateWindowOperatorInfo)); + SStateWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStateWindowOperatorInfo)); pInfo->colIndex = -1; pInfo->reptScan = false; pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "StateWindowOperator"; // pOperator->operatorType = OP_StateWindow; pOperator->blockingOptr = true; @@ -7763,8 +7763,8 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper } SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { - SSessionAggOperatorInfo* pInfo = calloc(1, sizeof(SSessionAggOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSessionAggOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7798,20 +7798,20 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo destroySWindowOperatorInfo(pInfo, numOfCols); } - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; } SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); + STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "MultiTableTimeIntervalOperator"; // pOperator->operatorType = OP_MultiTableTimeInterval; pOperator->blockingOptr = true; @@ -7829,13 +7829,13 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim } SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); + STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "AllMultiTableTimeIntervalOperator"; // pOperator->operatorType = OP_AllMultiTableTimeInterval; pOperator->blockingOptr = true; @@ -7868,7 +7868,7 @@ static int32_t initGroupOptrInfo(SGroupbyOperatorInfo *pInfo, SArray* pGroupColL key.bytes = pCol->bytes; key.type = pCol->type; key.isNull = false; - key.pData = calloc(1, pCol->bytes); + key.pData = taosMemoryCalloc(1, pCol->bytes); if (key.pData == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -7877,7 +7877,7 @@ static int32_t initGroupOptrInfo(SGroupbyOperatorInfo *pInfo, SArray* pGroupColL } int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols; - pInfo->keyBuf = calloc(1, pInfo->groupKeyLen + nullFlagSize); + pInfo->keyBuf = taosMemoryCalloc(1, pInfo->groupKeyLen + nullFlagSize); if (pInfo->keyBuf == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -7888,8 +7888,8 @@ static int32_t initGroupOptrInfo(SGroupbyOperatorInfo *pInfo, SArray* pGroupColL SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { - SGroupbyOperatorInfo* pInfo = calloc(1, sizeof(SGroupbyOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7918,8 +7918,8 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx return pOperator; _error: - tfree(pInfo); - tfree(pOperator); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); return NULL; } @@ -7939,7 +7939,7 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t taosCreateFillInfo(order, w.skey, 0, capacity, numOfCols, pInterval->sliding, pInterval->slidingUnit, (int8_t)pInterval->precision, fillType, pColInfo, id); - pInfo->p = calloc(numOfCols, POINTER_BYTES); + pInfo->p = taosMemoryCalloc(numOfCols, POINTER_BYTES); if (pInfo->pFillInfo == NULL || pInfo->p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -7950,8 +7950,8 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SInterval* pInterval, SSDataBlock* pResBlock, int32_t fillType, char* fillVal, bool multigroupResult, SExecTaskInfo* pTaskInfo) { - SFillOperatorInfo* pInfo = calloc(1, sizeof(SFillOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SFillOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SFillOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pInfo->pRes = pResBlock; pInfo->multigroupResult = multigroupResult; @@ -7980,14 +7980,14 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExp return pOperator; _error: - tfree(pOperator); - tfree(pInfo); + taosMemoryFreeClear(pOperator); + taosMemoryFreeClear(pInfo); return NULL; } SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput, void* pMerger, bool multigroupResult) { - SSLimitOperatorInfo* pInfo = calloc(1, sizeof(SSLimitOperatorInfo)); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SSLimitOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSLimitOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); // pInfo->orderColumnList = getResultGroupCheckColumns(pQueryAttr); // pInfo->slimit = pQueryAttr->slimit; @@ -8005,7 +8005,7 @@ SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorI } int32_t numOfCols = (pInfo->orderColumnList != NULL)? (int32_t) taosArrayGetSize(pInfo->orderColumnList):0; - pInfo->prevRow = calloc(1, (POINTER_BYTES * numOfCols + len)); + pInfo->prevRow = taosMemoryCalloc(1, (POINTER_BYTES * numOfCols + len)); int32_t offset = POINTER_BYTES * numOfCols; for(int32_t i = 0; i < numOfCols; ++i) { @@ -8164,7 +8164,7 @@ static SSDataBlock* doTagScan(SOperatorInfo *pOperator, bool* newgroup) { } SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput) { - STagScanInfo* pInfo = calloc(1, sizeof(STagScanInfo)); + STagScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STagScanInfo)); // pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); size_t numOfGroup = GET_NUM_OF_TABLEGROUP(pRuntimeEnv); @@ -8173,7 +8173,7 @@ SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo pInfo->totalTables = pRuntimeEnv->tableqinfoGroupInfo.numOfTables; pInfo->curPos = 0; - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "SeqTableTagScan"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; pOperator->blockingOptr = false; @@ -8207,7 +8207,7 @@ static bool initMultiDistinctInfo(SDistinctOperatorInfo *pInfo, SOperatorInfo* p } } pInfo->totalBytes += (int32_t)strlen(MULTI_KEY_DELIM) * (pOperator->numOfOutput); - pInfo->buf = calloc(1, pInfo->totalBytes); + pInfo->buf = taosMemoryCalloc(1, pInfo->totalBytes); return taosArrayGetSize(pInfo->pDistinctDataInfo) == pOperator->numOfOutput ? true : false; } @@ -8265,7 +8265,7 @@ static SSDataBlock* hashDistinct(SOperatorInfo *pOperator, bool* newgroup) { for (int i = 0; i < taosArrayGetSize(pRes->pDataBlock); i++) { SColumnInfoData* pResultColInfoData = taosArrayGet(pRes->pDataBlock, i); SDistinctDataInfo* pDistDataInfo = taosArrayGet(pInfo->pDistinctDataInfo, i); - char* tmp = realloc(pResultColInfoData->pData, newSize * pDistDataInfo->bytes); + char* tmp = taosMemoryRealloc(pResultColInfoData->pData, newSize * pDistDataInfo->bytes); if (tmp == NULL) { return NULL; } else { @@ -8301,7 +8301,7 @@ static SSDataBlock* hashDistinct(SOperatorInfo *pOperator, bool* newgroup) { } SOperatorInfo* createDistinctOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { - SDistinctOperatorInfo* pInfo = calloc(1, sizeof(SDistinctOperatorInfo)); + SDistinctOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SDistinctOperatorInfo)); pInfo->totalBytes = 0; pInfo->buf = NULL; pInfo->threshold = tsMaxNumOfDistinctResults; // distinct result threshold @@ -8311,7 +8311,7 @@ SOperatorInfo* createDistinctOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperato pInfo->pRes = createOutputBuf(pExpr, numOfOutput, (int32_t) pInfo->outputCapacity); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "DistinctOperator"; pOperator->blockingOptr = false; pOperator->status = OP_NOT_OPENED; @@ -8376,7 +8376,7 @@ static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t if (pColFilter->filterstr) { pColFilter->len = htobe64(pFilterMsg->len); - pColFilter->pz = (int64_t)calloc(1, (size_t)(pColFilter->len + 1 * TSDB_NCHAR_SIZE)); // note: null-terminator + pColFilter->pz = (int64_t)taosMemoryCalloc(1, (size_t)(pColFilter->len + 1 * TSDB_NCHAR_SIZE)); // note: null-terminator if (pColFilter->pz == 0) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -8415,7 +8415,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* } *numOfExprs = numOfFuncs + numOfGroupKeys; - SExprInfo* pExprs = calloc(*numOfExprs, sizeof(SExprInfo)); + SExprInfo* pExprs = taosMemoryCalloc(*numOfExprs, sizeof(SExprInfo)); for(int32_t i = 0; i < (*numOfExprs); ++i) { STargetNode* pTargetNode = NULL; @@ -8427,14 +8427,14 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* SExprInfo* pExp = &pExprs[pTargetNode->slotId]; - pExp->pExpr = calloc(1, sizeof(tExprNode)); + pExp->pExpr = taosMemoryCalloc(1, sizeof(tExprNode)); pExp->pExpr->_function.num = 1; pExp->pExpr->_function.functionId = -1; - pExp->base.pParam = calloc(1, sizeof(SFunctParam)); + pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); pExp->base.numOfParams = 1; - pExp->base.pParam[0].pCol = calloc(1, sizeof(SColumn)); + pExp->base.pParam[0].pCol = taosMemoryCalloc(1, sizeof(SColumn)); SColumn* pCol = pExp->base.pParam[0].pCol; // it is a project query, or group by column @@ -8478,13 +8478,13 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* } static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId) { - SExecTaskInfo* pTaskInfo = calloc(1, sizeof(SExecTaskInfo)); + SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo)); setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTaskInfo->cost.created = taosGetTimestampMs(); pTaskInfo->id.queryId = queryId; - char* p = calloc(1, 128); + char* p = taosMemoryCalloc(1, 128); snprintf(p, 128, "TID:0x%"PRIx64" QID:0x%"PRIx64, taskId, queryId); pTaskInfo->id.str = strdup(p); @@ -8607,7 +8607,7 @@ static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STa cond.order = pTableScanNode->scan.order; cond.numOfCols = LIST_LENGTH(pTableScanNode->scan.pScanCols); - cond.colList = calloc(cond.numOfCols, sizeof(SColumnInfo)); + cond.colList = taosMemoryCalloc(cond.numOfCols, sizeof(SColumnInfo)); if (cond.colList == NULL) { terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; @@ -8752,7 +8752,7 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead return code; _complete: - tfree(*pTaskInfo); + taosMemoryFreeClear(*pTaskInfo); terrno = code; return code; @@ -8763,7 +8763,7 @@ int32_t cloneExprFilterInfo(SColumnFilterInfo **dst, SColumnFilterInfo* src, int return TSDB_CODE_SUCCESS; } - *dst = calloc(filterNum, sizeof(*src)); + *dst = taosMemoryCalloc(filterNum, sizeof(*src)); if (*dst == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -8772,11 +8772,11 @@ int32_t cloneExprFilterInfo(SColumnFilterInfo **dst, SColumnFilterInfo* src, int for (int32_t i = 0; i < filterNum; i++) { if ((*dst)[i].filterstr && dst[i]->len > 0) { - void *pz = calloc(1, (size_t)(*dst)[i].len + 1); + void *pz = taosMemoryCalloc(1, (size_t)(*dst)[i].len + 1); if (pz == NULL) { if (i == 0) { - free(*dst); + taosMemoryFree(*dst); } else { freeColumnFilterInfo(*dst, i); } @@ -8836,7 +8836,7 @@ int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) { } //int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** pFilterInfo, uint64_t qId) { -// *pFilterInfo = calloc(1, sizeof(SSingleColumnFilterInfo) * numOfFilterCols); +// *pFilterInfo = taosMemoryCalloc(1, sizeof(SSingleColumnFilterInfo) * numOfFilterCols); // if (*pFilterInfo == NULL) { // return TSDB_CODE_QRY_OUT_OF_MEMORY; // } @@ -8849,7 +8849,7 @@ int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) { // pFilter->info = pCols[i]; // // pFilter->numOfFilters = pCols[i].flist.numOfFilters; -// pFilter->pFilters = calloc(pFilter->numOfFilters, sizeof(SColumnFilterElem)); +// pFilter->pFilters = taosMemoryCalloc(pFilter->numOfFilters, sizeof(SColumnFilterElem)); // if (pFilter->pFilters == NULL) { // return TSDB_CODE_QRY_OUT_OF_MEMORY; // } @@ -8891,11 +8891,11 @@ void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFil // if (pFilterInfo[i].pFilters->filterInfo.lowerRelOptr == TSDB_RELATION_IN) { // taosHashCleanup((SHashObj *)(pFilterInfo[i].pFilters->q)); // } -// tfree(pFilterInfo[i].pFilters); +// taosMemoryFreeClear(pFilterInfo[i].pFilters); // } // } // -// tfree(pFilterInfo); +// taosMemoryFreeClear(pFilterInfo); return NULL; } @@ -8987,11 +8987,11 @@ void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters) { for (int32_t i = 0; i < numOfFilters; i++) { if (pFilter[i].filterstr && pFilter[i].pz) { - free((void*)(pFilter[i].pz)); + taosMemoryFree((void*)(pFilter[i].pz)); } } - free(pFilter); + taosMemoryFree(pFilter); } static void doDestroyTableQueryInfo(STableGroupInfo* pTableqinfoGroupInfo) { @@ -9025,9 +9025,9 @@ void doDestroyTask(SExecTaskInfo *pTaskInfo) { // taosArrayDestroy(pTaskInfo->summary.queryProfEvents); // taosHashCleanup(pTaskInfo->summary.operatorProfResults); - tfree(pTaskInfo->sql); - tfree(pTaskInfo->id.str); - tfree(pTaskInfo); + taosMemoryFreeClear(pTaskInfo->sql); + taosMemoryFreeClear(pTaskInfo->id.str); + taosMemoryFreeClear(pTaskInfo); } static void doSetTagValueToResultBuf(char* output, const char* val, int16_t type, int16_t bytes) { diff --git a/source/libs/executor/src/tlinearhash.c b/source/libs/executor/src/tlinearhash.c index 28319469cc..1b55467c85 100644 --- a/source/libs/executor/src/tlinearhash.c +++ b/source/libs/executor/src/tlinearhash.c @@ -209,7 +209,7 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { newLen += 4; } - char* p = realloc(pHashObj->pBucket, POINTER_BYTES * newLen); + char* p = taosMemoryRealloc(pHashObj->pBucket, POINTER_BYTES * newLen); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -219,7 +219,7 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { pHashObj->numOfAlloc = newLen; } - SLHashBucket* pBucket = calloc(1, sizeof(SLHashBucket)); + SLHashBucket* pBucket = taosMemoryCalloc(1, sizeof(SLHashBucket)); pHashObj->pBucket[pHashObj->numOfBuckets] = pBucket; pBucket->pPageIdList = taosArrayInit(2, sizeof(int32_t)); @@ -241,7 +241,7 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { } SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_t numOfTuplePerPage) { - SLHashObj* pHashObj = calloc(1, sizeof(SLHashObj)); + SLHashObj* pHashObj = taosMemoryCalloc(1, sizeof(SLHashObj)); if (pHashObj == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -265,12 +265,12 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_ pHashObj->tuplesPerPage = numOfTuplePerPage; pHashObj->numOfAlloc = 4; // initial allocated array list - pHashObj->pBucket = calloc(pHashObj->numOfAlloc, POINTER_BYTES); + pHashObj->pBucket = taosMemoryCalloc(pHashObj->numOfAlloc, POINTER_BYTES); code = doAddNewBucket(pHashObj); if (code != TSDB_CODE_SUCCESS) { destroyDiskbasedBuf(pHashObj->pBuf); - tfree(pHashObj); + taosMemoryFreeClear(pHashObj); terrno = code; return NULL; } @@ -282,11 +282,11 @@ void* tHashCleanup(SLHashObj* pHashObj) { destroyDiskbasedBuf(pHashObj->pBuf); for(int32_t i = 0; i < pHashObj->numOfBuckets; ++i) { taosArrayDestroy(pHashObj->pBucket[i]->pPageIdList); - tfree(pHashObj->pBucket[i]); + taosMemoryFreeClear(pHashObj->pBucket[i]); } - tfree(pHashObj->pBucket); - tfree(pHashObj); + taosMemoryFreeClear(pHashObj->pBucket); + taosMemoryFreeClear(pHashObj); return NULL; } diff --git a/source/libs/executor/src/tsimplehash.c b/source/libs/executor/src/tsimplehash.c index 65067f58e3..981da0415e 100644 --- a/source/libs/executor/src/tsimplehash.c +++ b/source/libs/executor/src/tsimplehash.c @@ -29,7 +29,7 @@ #define FREE_HASH_NODE(_n) \ do { \ - tfree(_n); \ + taosMemoryFreeClear(_n); \ } while (0); typedef struct SHNode { @@ -62,7 +62,7 @@ SSHashObj *tSimpleHashInit(size_t capacity, _hash_fn_t fn, size_t keyLen, size_t capacity = 4; } - SSHashObj* pHashObj = (SSHashObj*) calloc(1, sizeof(SSHashObj)); + SSHashObj* pHashObj = (SSHashObj*) taosMemoryCalloc(1, sizeof(SSHashObj)); if (pHashObj == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -78,9 +78,9 @@ SSHashObj *tSimpleHashInit(size_t capacity, _hash_fn_t fn, size_t keyLen, size_t pHashObj->keyLen = keyLen; pHashObj->dataLen = dataLen; - pHashObj->hashList = (SHNode **)calloc(pHashObj->capacity, sizeof(void *)); + pHashObj->hashList = (SHNode **)taosMemoryCalloc(pHashObj->capacity, sizeof(void *)); if (pHashObj->hashList == NULL) { - free(pHashObj); + taosMemoryFree(pHashObj); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -95,7 +95,7 @@ int32_t tSimpleHashGetSize(const SSHashObj *pHashObj) { } static SHNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, size_t dsize, uint32_t hashVal) { - SHNode *pNewNode = malloc(sizeof(SHNode) + keyLen + dsize); + SHNode *pNewNode = taosMemoryMalloc(sizeof(SHNode) + keyLen + dsize); if (pNewNode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -120,7 +120,7 @@ void taosHashTableResize(SSHashObj *pHashObj) { } int64_t st = taosGetTimestampUs(); - void *pNewEntryList = realloc(pHashObj->hashList, sizeof(void *) * newCapacity); + void *pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(void *) * newCapacity); if (pNewEntryList == NULL) { // qWarn("hash resize failed due to out of memory, capacity remain:%zu", pHashObj->capacity); return; @@ -287,7 +287,7 @@ void tSimpleHashCleanup(SSHashObj *pHashObj) { } tSimpleHashClear(pHashObj); - tfree(pHashObj->hashList); + taosMemoryFreeClear(pHashObj->hashList); } size_t tSimpleHashGetMemSize(const SSHashObj *pHashObj) { diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index d424599758..85ba462c9a 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -65,7 +65,7 @@ typedef struct SSortHandle { static int32_t msortComparFn(const void *pLeft, const void *pRight, void *param); static SSDataBlock* createDataBlock_rv(SSchema* pSchema, int32_t numOfCols) { - SSDataBlock* pBlock = calloc(1, sizeof(SSDataBlock)); + SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); pBlock->info.numOfCols = numOfCols; @@ -91,7 +91,7 @@ static SSDataBlock* createDataBlock_rv(SSchema* pSchema, int32_t numOfCols) { * @return */ SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, bool nullFirst, int32_t type, int32_t pageSize, int32_t numOfPages, SSchema* pSchema, int32_t numOfCols, const char* idstr) { - SSortHandle* pSortHandle = calloc(1, sizeof(SSortHandle)); + SSortHandle* pSortHandle = taosMemoryCalloc(1, sizeof(SSortHandle)); pSortHandle->type = type; pSortHandle->pageSize = pageSize; @@ -118,8 +118,8 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { } destroyDiskbasedBuf(pSortHandle->pBuf); - tfree(pSortHandle->idStr); - tfree(pSortHandle); + taosMemoryFreeClear(pSortHandle->idStr); + taosMemoryFreeClear(pSortHandle); } int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource) { @@ -127,7 +127,7 @@ int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource) { } static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSources, SSDataBlock* pBlock, int32_t* sourceId) { - SExternalMemSource* pSource = calloc(1, sizeof(SExternalMemSource)); + SExternalMemSource* pSource = taosMemoryCalloc(1, sizeof(SExternalMemSource)); if (pSource == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -233,7 +233,7 @@ static int32_t sortComparClearup(SMsortComparParam* cmpParam) { for(int32_t i = 0; i < cmpParam->numOfSources; ++i) { SExternalMemSource* pSource = cmpParam->pSources[i]; blockDataDestroy(pSource->src.pBlock); - tfree(pSource); + taosMemoryFreeClear(pSource); } cmpParam->numOfSources = 0; @@ -570,7 +570,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { } } - tfree(source); + taosMemoryFreeClear(source); } return TSDB_CODE_SUCCESS; diff --git a/source/libs/executor/test/executorTests.cpp b/source/libs/executor/test/executorTests.cpp index 2f1caab30b..7fb9b2ad7e 100644 --- a/source/libs/executor/test/executorTests.cpp +++ b/source/libs/executor/test/executorTests.cpp @@ -62,7 +62,7 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { } if (pInfo->pBlock == NULL) { - pInfo->pBlock = static_cast(calloc(1, sizeof(SSDataBlock))); + pInfo->pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); pInfo->pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); @@ -70,8 +70,8 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { colInfo.info.type = TSDB_DATA_TYPE_INT; colInfo.info.bytes = sizeof(int32_t); colInfo.info.colId = 1; - colInfo.pData = static_cast(calloc(pInfo->numOfRowsPerPage, sizeof(int32_t))); - colInfo.nullbitmap = static_cast(calloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); + colInfo.pData = static_cast(taosMemoryCalloc(pInfo->numOfRowsPerPage, sizeof(int32_t))); + colInfo.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo); @@ -82,7 +82,7 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { // // colInfo1.varmeta.allocLen = 0;//numOfRows * sizeof(int32_t); // colInfo1.varmeta.length = 0; -// colInfo1.varmeta.offset = static_cast(calloc(1, numOfRows * sizeof(int32_t))); +// colInfo1.varmeta.offset = static_cast(taosMemoryCalloc(1, numOfRows * sizeof(int32_t))); // // taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1); } else { @@ -128,7 +128,7 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { } if (pInfo->pBlock == NULL) { - pInfo->pBlock = static_cast(calloc(1, sizeof(SSDataBlock))); + pInfo->pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); pInfo->pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); @@ -136,8 +136,8 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { colInfo.info.type = TSDB_DATA_TYPE_TIMESTAMP; colInfo.info.bytes = sizeof(int64_t); colInfo.info.colId = 1; - colInfo.pData = static_cast(calloc(pInfo->numOfRowsPerPage, sizeof(int64_t))); -// colInfo.nullbitmap = static_cast(calloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); + colInfo.pData = static_cast(taosMemoryCalloc(pInfo->numOfRowsPerPage, sizeof(int64_t))); +// colInfo.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo); @@ -146,8 +146,8 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { colInfo1.info.bytes = 4; colInfo1.info.colId = 2; - colInfo1.pData = static_cast(calloc(pInfo->numOfRowsPerPage, sizeof(int32_t))); - colInfo1.nullbitmap = static_cast(calloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); + colInfo1.pData = static_cast(taosMemoryCalloc(pInfo->numOfRowsPerPage, sizeof(int32_t))); + colInfo1.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1); } else { @@ -195,7 +195,7 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) { } SOperatorInfo* createDummyOperator(int32_t startVal, int32_t numOfBlocks, int32_t rowsPerPage, int32_t type, int32_t numOfCols) { - SOperatorInfo* pOperator = static_cast(calloc(1, sizeof(SOperatorInfo))); + SOperatorInfo* pOperator = static_cast(taosMemoryCalloc(1, sizeof(SOperatorInfo))); pOperator->name = "dummyInputOpertor4Test"; if (numOfCols == 1) { @@ -204,7 +204,7 @@ SOperatorInfo* createDummyOperator(int32_t startVal, int32_t numOfBlocks, int32_ pOperator->getNextFn = get2ColsDummyBlock; } - SDummyInputInfo *pInfo = (SDummyInputInfo*) calloc(1, sizeof(SDummyInputInfo)); + SDummyInputInfo *pInfo = (SDummyInputInfo*) taosMemoryCalloc(1, sizeof(SDummyInputInfo)); pInfo->totalPages = numOfBlocks; pInfo->startVal = startVal; pInfo->numOfRowsPerPage = rowsPerPage; @@ -958,11 +958,11 @@ TEST(testCase, inMem_sort_Test) { taosArrayPush(pOrderVal, &o); SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo)); - SExprInfo *exp = static_cast(calloc(1, sizeof(SExprInfo))); + SExprInfo *exp = static_cast(taosMemoryCalloc(1, sizeof(SExprInfo))); exp->base.resSchema = createSchema(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1, "res"); taosArrayPush(pExprInfo, &exp); - SExprInfo *exp1 = static_cast(calloc(1, sizeof(SExprInfo))); + SExprInfo *exp1 = static_cast(taosMemoryCalloc(1, sizeof(SExprInfo))); exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1"); taosArrayPush(pExprInfo, &exp1); @@ -1002,10 +1002,10 @@ int32_t cmp(const void* p1, const void* p2) { #if 0 TEST(testCase, external_sort_Test) { #if 0 - su* v = static_cast(calloc(1000000, sizeof(su))); + su* v = static_cast(taosMemoryCalloc(1000000, sizeof(su))); for(int32_t i = 0; i < 1000000; ++i) { v[i].v = taosRand(); - v[i].c = static_cast(malloc(4)); + v[i].c = static_cast(taosMemoryMalloc(4)); *(int32_t*) v[i].c = i; } @@ -1027,11 +1027,11 @@ TEST(testCase, external_sort_Test) { taosArrayPush(pOrderVal, &o); SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo)); - SExprInfo *exp = static_cast(calloc(1, sizeof(SExprInfo))); + SExprInfo *exp = static_cast(taosMemoryCalloc(1, sizeof(SExprInfo))); exp->base.resSchema = createSchema(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1, "res"); taosArrayPush(pExprInfo, &exp); - SExprInfo *exp1 = static_cast(calloc(1, sizeof(SExprInfo))); + SExprInfo *exp1 = static_cast(taosMemoryCalloc(1, sizeof(SExprInfo))); exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1"); // taosArrayPush(pExprInfo, &exp1); @@ -1071,8 +1071,8 @@ TEST(testCase, external_sort_Test) { printf("total:%ld\n", s2 - s1); pOperator->closeFn(pOperator->info, 2); - tfree(exp); - tfree(exp1); + taosMemoryFreeClear(exp); + taosMemoryFreeClear(exp1); taosArrayDestroy(pExprInfo); taosArrayDestroy(pOrderVal); } @@ -1088,21 +1088,21 @@ TEST(testCase, sorted_merge_Test) { taosArrayPush(pOrderVal, &o); SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo)); - SExprInfo *exp = static_cast(calloc(1, sizeof(SExprInfo))); + SExprInfo *exp = static_cast(taosMemoryCalloc(1, sizeof(SExprInfo))); exp->base.resSchema = createSchema(TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 1, "count_result"); - exp->base.pColumns = static_cast(calloc(1, sizeof(SColumn))); + exp->base.pColumns = static_cast(taosMemoryCalloc(1, sizeof(SColumn))); exp->base.pColumns->flag = TSDB_COL_NORMAL; exp->base.pColumns->info = (SColumnInfo) {.colId = 1, .type = TSDB_DATA_TYPE_INT, .bytes = 4}; exp->base.numOfCols = 1; taosArrayPush(pExprInfo, &exp); - SExprInfo *exp1 = static_cast(calloc(1, sizeof(SExprInfo))); + SExprInfo *exp1 = static_cast(taosMemoryCalloc(1, sizeof(SExprInfo))); exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1"); // taosArrayPush(pExprInfo, &exp1); int32_t numOfSources = 10; - SOperatorInfo** plist = (SOperatorInfo**) calloc(numOfSources, sizeof(void*)); + SOperatorInfo** plist = (SOperatorInfo**) taosMemoryCalloc(numOfSources, sizeof(void*)); for(int32_t i = 0; i < numOfSources; ++i) { plist[i] = createDummyOperator(1, 1, 1, data_asc, 1); } @@ -1143,8 +1143,8 @@ TEST(testCase, sorted_merge_Test) { printf("total:%ld\n", s2 - s1); pOperator->closeFn(pOperator->info, 2); - tfree(exp); - tfree(exp1); + taosMemoryFreeClear(exp); + taosMemoryFreeClear(exp1); taosArrayDestroy(pExprInfo); taosArrayDestroy(pOrderVal); } @@ -1160,18 +1160,18 @@ TEST(testCase, time_interval_Operator_Test) { taosArrayPush(pOrderVal, &o); SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo)); - SExprInfo *exp = static_cast(calloc(1, sizeof(SExprInfo))); + SExprInfo *exp = static_cast(taosMemoryCalloc(1, sizeof(SExprInfo))); exp->base.resSchema = createSchema(TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 1, "ts"); - exp->base.pColumns = static_cast(calloc(1, sizeof(SColumn))); + exp->base.pColumns = static_cast(taosMemoryCalloc(1, sizeof(SColumn))); exp->base.pColumns->flag = TSDB_COL_NORMAL; exp->base.pColumns->info = (SColumnInfo) {.colId = 1, .type = TSDB_DATA_TYPE_TIMESTAMP, .bytes = 8}; exp->base.numOfCols = 1; taosArrayPush(pExprInfo, &exp); - SExprInfo *exp1 = static_cast(calloc(1, sizeof(SExprInfo))); + SExprInfo *exp1 = static_cast(taosMemoryCalloc(1, sizeof(SExprInfo))); exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BIGINT, 8, 2, "res1"); - exp1->base.pColumns = static_cast(calloc(1, sizeof(SColumn))); + exp1->base.pColumns = static_cast(taosMemoryCalloc(1, sizeof(SColumn))); exp1->base.pColumns->flag = TSDB_COL_NORMAL; exp1->base.pColumns->info = (SColumnInfo) {.colId = 1, .type = TSDB_DATA_TYPE_INT, .bytes = 4}; exp1->base.numOfCols = 1; @@ -1221,8 +1221,8 @@ TEST(testCase, time_interval_Operator_Test) { printf("total:%ld\n", s2 - s1); pOperator->closeFn(pOperator->info, 2); - tfree(exp); - tfree(exp1); + taosMemoryFreeClear(exp); + taosMemoryFreeClear(exp1); taosArrayDestroy(pExprInfo); taosArrayDestroy(pOrderVal); } diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 1956794395..586aed7a67 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -47,15 +47,15 @@ SSDataBlock* getSingleColDummyBlock(void* param) { return NULL; } - SSDataBlock* pBlock = static_cast(calloc(1, sizeof(SSDataBlock))); + SSDataBlock* pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); SColumnInfoData colInfo = {0}; colInfo.info.type = TSDB_DATA_TYPE_INT; colInfo.info.bytes = sizeof(int32_t); colInfo.info.colId = 1; - colInfo.pData = static_cast(calloc(pInfo->pageRows, sizeof(int32_t))); - colInfo.nullbitmap = static_cast(calloc(1, (pInfo->pageRows + 7) / 8)); + colInfo.pData = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); + colInfo.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->pageRows + 7) / 8)); taosArrayPush(pBlock->pDataBlock, &colInfo); @@ -203,12 +203,12 @@ TEST(testCase, external_mem_sort_Test) { SSortHandle* phandle = tsortCreateSortHandle(orderInfo, false, SORT_SINGLESOURCE_SORT, 1024, 5, &s, 1, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); - _info* pInfo = (_info*) calloc(1, sizeof(_info)); + _info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info)); pInfo->startVal = 100000; pInfo->pageRows = 1000; pInfo->count = 50; - SGenericSource* ps = static_cast(calloc(1, sizeof(SGenericSource))); + SGenericSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); ps->param = pInfo; tsortAddSource(phandle, ps); @@ -249,8 +249,8 @@ TEST(testCase, ordered_merge_sort_Test) { tsortSetComparFp(phandle, docomp); for(int32_t i = 0; i < 10; ++i) { - SGenericSource* p = static_cast(calloc(1, sizeof(SGenericSource))); - _info* c = static_cast<_info*>(calloc(1, sizeof(_info))); + SGenericSource* p = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); + _info* c = static_cast<_info*>(taosMemoryCalloc(1, sizeof(_info))); c->count = 1; c->pageRows = 1000; c->startVal = 0; diff --git a/source/libs/function/CMakeLists.txt b/source/libs/function/CMakeLists.txt index 6305d242ac..5c01ec78f0 100644 --- a/source/libs/function/CMakeLists.txt +++ b/source/libs/function/CMakeLists.txt @@ -21,6 +21,7 @@ target_include_directories( PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/function" "${CMAKE_SOURCE_DIR}/contrib/libuv/include" + "${CMAKE_SOURCE_DIR}/include/os" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( @@ -34,6 +35,7 @@ target_include_directories( udf1 PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/function" + "${CMAKE_SOURCE_DIR}/include/os" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) diff --git a/source/libs/function/src/taggfunction.c b/source/libs/function/src/taggfunction.c index 4360515328..05ed30c61a 100644 --- a/source/libs/function/src/taggfunction.c +++ b/source/libs/function/src/taggfunction.c @@ -1929,7 +1929,7 @@ static void copyTopBotRes(SqlFunctionCtx *pCtx, int32_t type) { // set the corresponding tag data for each record // todo check malloc failure -// char **pData = calloc(pCtx->tagInfo.numOfTagCols, POINTER_BYTES); +// char **pData = taosMemoryCalloc(pCtx->tagInfo.numOfTagCols, POINTER_BYTES); // for (int32_t i = 0; i < pCtx->tagInfo.numOfTagCols; ++i) { // pData[i] = pCtx->tagInfo.pTagCtxList[i]->pOutput; // } @@ -1943,7 +1943,7 @@ static void copyTopBotRes(SqlFunctionCtx *pCtx, int32_t type) { // } // } -// tfree(pData); +// taosMemoryFreeClear(pData); } /* @@ -2422,7 +2422,7 @@ static void apercentile_finalizer(SqlFunctionCtx *pCtx) { // double *res = tHistogramUniform(pOutput->pHisto, ratio, 1); // // memcpy(pCtx->pOutput, res, sizeof(double)); -// free(res); +// taosMemoryFree(res); // } else { // setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes); // return; @@ -2433,7 +2433,7 @@ static void apercentile_finalizer(SqlFunctionCtx *pCtx) { double *res = tHistogramUniform(pOutput->pHisto, ratio, 1); memcpy(pCtx->pOutput, res, sizeof(double)); - free(res); + taosMemoryFree(res); } else { // no need to free setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes); return; @@ -4004,7 +4004,7 @@ static void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDi char* outputBuf = NULL; if (comp) { - outputBuf = malloc(originalLen); + outputBuf = taosMemoryMalloc(originalLen); size_t actualLen = compLen; const char* compStr = tbufReadBinary(&br, &actualLen); @@ -4018,7 +4018,7 @@ static void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDi pDist->dataBlockInfos = taosArrayFromList(outputBuf, (uint32_t)numSteps, sizeof(SFileBlockInfo)); if (comp) { - tfree(outputBuf); + taosMemoryFreeClear(outputBuf); } } diff --git a/source/libs/function/src/texpr.c b/source/libs/function/src/texpr.c index bede8b80fd..814aa48b55 100644 --- a/source/libs/function/src/texpr.c +++ b/source/libs/function/src/texpr.c @@ -52,10 +52,10 @@ void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) { } else if (pNode->nodeType == TEXPR_VALUE_NODE) { taosVariantDestroy(pNode->pVal); } else if (pNode->nodeType == TEXPR_COL_NODE) { - tfree(pNode->pSchema); + taosMemoryFreeClear(pNode->pSchema); } - free(pNode); + taosMemoryFree(pNode); } static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) { @@ -80,12 +80,12 @@ static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) { assert((*pExpr)->_node.pRight == NULL); } else if (type == TEXPR_VALUE_NODE) { taosVariantDestroy((*pExpr)->pVal); - free((*pExpr)->pVal); + taosMemoryFree((*pExpr)->pVal); } else if (type == TEXPR_COL_NODE) { - free((*pExpr)->pSchema); + taosMemoryFree((*pExpr)->pSchema); } - free(*pExpr); + taosMemoryFree(*pExpr); *pExpr = NULL; } @@ -154,7 +154,7 @@ void exprTreeToBinary(SBufferWriter* bw, tExprNode* expr) { // TODO: these three functions should be made global static void* exception_calloc(size_t nmemb, size_t size) { - void* p = calloc(nmemb, size); + void* p = taosMemoryCalloc(nmemb, size); if (p == NULL) { THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -162,7 +162,7 @@ static void* exception_calloc(size_t nmemb, size_t size) { } static void* exception_malloc(size_t size) { - void* p = malloc(size); + void* p = taosMemoryMalloc(size); if (p == NULL) { THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -195,7 +195,7 @@ static tExprNode* exprTreeFromBinaryImpl(SBufferReader* br) { pVal->nType = tbufReadUint32(br); if (pVal->nType == TSDB_DATA_TYPE_BINARY) { tbufReadToBuffer(br, &pVal->nLen, sizeof(pVal->nLen)); - pVal->pz = calloc(1, pVal->nLen + 1); + pVal->pz = taosMemoryCalloc(1, pVal->nLen + 1); tbufReadToBuffer(br, pVal->pz, pVal->nLen); } else { pVal->i = tbufReadInt64(br); @@ -377,7 +377,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t bufLen = 128; } - char *tmp = calloc(1, bufLen * TSDB_NCHAR_SIZE); + char *tmp = taosMemoryCalloc(1, bufLen * TSDB_NCHAR_SIZE); for (int32_t i = 0; i < sz; i++) { switch (sType) { @@ -440,7 +440,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t taosVariantCreateFromBinary(&tmpVar, (char *)pvar, t, sType); if (bufLen < t) { - tmp = realloc(tmp, t * TSDB_NCHAR_SIZE); + tmp = taosMemoryRealloc(tmp, t * TSDB_NCHAR_SIZE); bufLen = (int32_t)t; } @@ -530,7 +530,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t err_ret: taosVariantDestroy(&tmpVar); taosHashCleanup(pObj); - tfree(tmp); + taosMemoryFreeClear(tmp); } tExprNode* exprdup(tExprNode* pNode) { @@ -538,7 +538,7 @@ tExprNode* exprdup(tExprNode* pNode) { return NULL; } - tExprNode* pCloned = calloc(1, sizeof(tExprNode)); + tExprNode* pCloned = taosMemoryCalloc(1, sizeof(tExprNode)); if (pNode->nodeType == TEXPR_BINARYEXPR_NODE) { tExprNode* pLeft = exprdup(pNode->_node.pLeft); tExprNode* pRight = exprdup(pNode->_node.pRight); @@ -547,17 +547,17 @@ tExprNode* exprdup(tExprNode* pNode) { pCloned->_node.pRight = pRight; pCloned->_node.optr = pNode->_node.optr; } else if (pNode->nodeType == TEXPR_VALUE_NODE) { - pCloned->pVal = calloc(1, sizeof(SVariant)); + pCloned->pVal = taosMemoryCalloc(1, sizeof(SVariant)); taosVariantAssign(pCloned->pVal, pNode->pVal); } else if (pNode->nodeType == TEXPR_COL_NODE) { - pCloned->pSchema = calloc(1, sizeof(SSchema)); + pCloned->pSchema = taosMemoryCalloc(1, sizeof(SSchema)); *pCloned->pSchema = *pNode->pSchema; } else if (pNode->nodeType == TEXPR_FUNCTION_NODE) { strcpy(pCloned->_function.functionName, pNode->_function.functionName); int32_t num = pNode->_function.num; pCloned->_function.num = num; - pCloned->_function.pChild = calloc(num, POINTER_BYTES); + pCloned->_function.pChild = taosMemoryCalloc(num, POINTER_BYTES); for(int32_t i = 0; i < num; ++i) { pCloned->_function.pChild[i] = exprdup(pNode->_function.pChild[i]); } diff --git a/source/libs/function/src/tfill.c b/source/libs/function/src/tfill.c index 9b3dca7393..1f7e83286b 100644 --- a/source/libs/function/src/tfill.c +++ b/source/libs/function/src/tfill.c @@ -149,7 +149,7 @@ static void initBeforeAfterDataBuf(SFillInfo* pFillInfo, char** next) { return; } - *next = calloc(1, pFillInfo->rowSize); + *next = taosMemoryCalloc(1, pFillInfo->rowSize); for (int i = 1; i < pFillInfo->numOfCols; i++) { SFillColInfo* pCol = &pFillInfo->pFillCol[i]; setNull(*next + pCol->col.offset, pCol->col.type, pCol->col.bytes); @@ -258,7 +258,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, void** data, int32_t outputR 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); + taosMemoryFreeClear(*next); } pFillInfo->numOfTotal += pFillInfo->numOfCurrent; @@ -314,7 +314,7 @@ static int32_t setTagColumnInfo(SFillInfo* pFillInfo, int32_t numOfCols, int32_t pSchema->type = pColInfo->col.type; pSchema->bytes = pColInfo->col.bytes; - pFillInfo->pTags[k].tagVal = calloc(1, pColInfo->col.bytes); + pFillInfo->pTags[k].tagVal = taosMemoryCalloc(1, pColInfo->col.bytes); pColInfo->tagIndex = k; k += 1; @@ -347,7 +347,7 @@ struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTag return NULL; } - SFillInfo* pFillInfo = calloc(1, sizeof(SFillInfo)); + SFillInfo* pFillInfo = taosMemoryCalloc(1, sizeof(SFillInfo)); taosResetFillInfo(pFillInfo, skey); pFillInfo->order = order; @@ -364,10 +364,10 @@ struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTag pFillInfo->interval.sliding = slidingTime; pFillInfo->interval.slidingUnit = slidingUnit; - pFillInfo->pData = malloc(POINTER_BYTES * numOfCols); + pFillInfo->pData = taosMemoryMalloc(POINTER_BYTES * numOfCols); // if (numOfTags > 0) { - pFillInfo->pTags = calloc(numOfCols, sizeof(SFillTagColInfo)); + pFillInfo->pTags = taosMemoryCalloc(numOfCols, sizeof(SFillTagColInfo)); for (int32_t i = 0; i < numOfCols; ++i) { pFillInfo->pTags[i].col.colId = -2; // TODO } @@ -394,19 +394,19 @@ void* taosDestroyFillInfo(SFillInfo* pFillInfo) { return NULL; } - tfree(pFillInfo->prevValues); - tfree(pFillInfo->nextValues); + taosMemoryFreeClear(pFillInfo->prevValues); + taosMemoryFreeClear(pFillInfo->nextValues); for(int32_t i = 0; i < pFillInfo->numOfTags; ++i) { - tfree(pFillInfo->pTags[i].tagVal); + taosMemoryFreeClear(pFillInfo->pTags[i].tagVal); } - tfree(pFillInfo->pTags); + taosMemoryFreeClear(pFillInfo->pTags); - tfree(pFillInfo->pData); - tfree(pFillInfo->pFillCol); + taosMemoryFreeClear(pFillInfo->pData); + taosMemoryFreeClear(pFillInfo->pFillCol); - tfree(pFillInfo); + taosMemoryFreeClear(pFillInfo); return NULL; } @@ -530,7 +530,7 @@ int64_t getFillInfoStart(struct SFillInfo *pFillInfo) { struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, const int64_t* fillVal) { int32_t offset = 0; - struct SFillColInfo* pFillCol = calloc(numOfOutput, sizeof(SFillColInfo)); + struct SFillColInfo* pFillCol = taosMemoryCalloc(numOfOutput, sizeof(SFillColInfo)); if (pFillCol == NULL) { return NULL; } diff --git a/source/libs/function/src/thistogram.c b/source/libs/function/src/thistogram.c index 49799aef7a..2e60498aba 100644 --- a/source/libs/function/src/thistogram.c +++ b/source/libs/function/src/thistogram.c @@ -34,11 +34,11 @@ static int32_t histogramCreateBin(SHistogramInfo* pHisto, int32_t index, double SHistogramInfo* tHistogramCreate(int32_t numOfEntries) { /* need one redundant slot */ - SHistogramInfo* pHisto = malloc(sizeof(SHistogramInfo) + sizeof(SHistBin) * (numOfEntries + 1)); + SHistogramInfo* pHisto = taosMemoryMalloc(sizeof(SHistogramInfo) + sizeof(SHistBin) * (numOfEntries + 1)); #if !defined(USE_ARRAYLIST) pHisto->pList = SSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); - SInsertSupporter* pss = malloc(sizeof(SInsertSupporter)); + SInsertSupporter* pss = taosMemoryMalloc(sizeof(SInsertSupporter)); pss->numOfEntries = pHisto->maxEntries; pss->pSkipList = pHisto->pList; @@ -96,7 +96,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) { } #else tSkipListKey key = tSkipListCreateKey(TSDB_DATA_TYPE_DOUBLE, &val, tDataTypes[TSDB_DATA_TYPE_DOUBLE].nSize); - SHistBin* entry = calloc(1, sizeof(SHistBin)); + SHistBin* entry = taosMemoryCalloc(1, sizeof(SHistBin)); entry->val = val; tSkipListNode* pResNode = SSkipListPut((*pHisto)->pList, entry, &key, 0); @@ -352,7 +352,7 @@ void tHistogramDestroy(SHistogramInfo** pHisto) { return; } - free(*pHisto); + taosMemoryFree(*pHisto); *pHisto = NULL; } @@ -417,7 +417,7 @@ int64_t tHistogramSum(SHistogramInfo* pHisto, double v) { double* tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num) { #if defined(USE_ARRAYLIST) - double* pVal = malloc(num * sizeof(double)); + double* pVal = taosMemoryMalloc(num * sizeof(double)); for (int32_t i = 0; i < num; ++i) { double numOfElem = (ratio[i] / 100) * pHisto->numOfElems; @@ -463,7 +463,7 @@ double* tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num) { } } #else - double* pVal = malloc(num * sizeof(double)); + double* pVal = taosMemoryMalloc(num * sizeof(double)); for (int32_t i = 0; i < num; ++i) { double numOfElem = ratio[i] * pHisto->numOfElems; @@ -535,7 +535,7 @@ SHistogramInfo* tHistogramMerge(SHistogramInfo* pHisto1, SHistogramInfo* pHisto2 return pResHistogram; } - SHistBin* pHistoBins = calloc(1, sizeof(SHistBin) * (pHisto1->numOfEntries + pHisto2->numOfEntries)); + SHistBin* pHistoBins = taosMemoryCalloc(1, sizeof(SHistBin) * (pHisto1->numOfEntries + pHisto2->numOfEntries)); int32_t i = 0, j = 0, k = 0; while (i < pHisto1->numOfEntries && j < pHisto2->numOfEntries) { @@ -573,6 +573,6 @@ SHistogramInfo* tHistogramMerge(SHistogramInfo* pHisto1, SHistogramInfo* pHisto2 pResHistogram->numOfEntries = k; memcpy(pResHistogram->elems, pHistoBins, sizeof(SHistBin) * k); - free(pHistoBins); + taosMemoryFree(pHistoBins); return pResHistogram; } diff --git a/source/libs/function/src/tpercentile.c b/source/libs/function/src/tpercentile.c index 06c58430a4..dd57024624 100644 --- a/source/libs/function/src/tpercentile.c +++ b/source/libs/function/src/tpercentile.c @@ -29,7 +29,7 @@ int32_t getGroupId(int32_t numOfSlots, int32_t slotIndex, int32_t times) { } static SFilePage *loadDataFromFilePage(tMemBucket *pMemBucket, int32_t slotIdx) { - SFilePage *buffer = (SFilePage *)calloc(1, pMemBucket->bytes * pMemBucket->pSlots[slotIdx].info.size + sizeof(SFilePage)); + SFilePage *buffer = (SFilePage *)taosMemoryCalloc(1, pMemBucket->bytes * pMemBucket->pSlots[slotIdx].info.size + sizeof(SFilePage)); int32_t groupId = getGroupId(pMemBucket->numOfSlots, slotIdx, pMemBucket->times); SIDList list = getDataBufPagesIdList(pMemBucket->pBuffer, groupId); @@ -216,7 +216,7 @@ static void resetSlotInfo(tMemBucket* pBucket) { } tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, double maxval) { - tMemBucket *pBucket = (tMemBucket *)calloc(1, sizeof(tMemBucket)); + tMemBucket *pBucket = (tMemBucket *)taosMemoryCalloc(1, sizeof(tMemBucket)); if (pBucket == NULL) { return NULL; } @@ -233,7 +233,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, if (setBoundingBox(&pBucket->range, pBucket->type, minval, maxval) != 0) { // qError("MemBucket:%p, invalid value range: %f-%f", pBucket, minval, maxval); - free(pBucket); + taosMemoryFree(pBucket); return NULL; } @@ -243,13 +243,13 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, pBucket->hashFunc = getHashFunc(pBucket->type); if (pBucket->hashFunc == NULL) { // qError("MemBucket:%p, not support data type %d, failed", pBucket, pBucket->type); - free(pBucket); + taosMemoryFree(pBucket); return NULL; } - pBucket->pSlots = (tMemBucketSlot *)calloc(pBucket->numOfSlots, sizeof(tMemBucketSlot)); + pBucket->pSlots = (tMemBucketSlot *)taosMemoryCalloc(pBucket->numOfSlots, sizeof(tMemBucketSlot)); if (pBucket->pSlots == NULL) { - free(pBucket); + taosMemoryFree(pBucket); return NULL; } @@ -271,8 +271,8 @@ void tMemBucketDestroy(tMemBucket *pBucket) { } destroyDiskbasedBuf(pBucket->pBuffer); - tfree(pBucket->pSlots); - tfree(pBucket); + taosMemoryFreeClear(pBucket->pSlots); + taosMemoryFreeClear(pBucket); } void tMemBucketUpdateBoundingBox(MinMaxEntry *r, const char *data, int32_t dataType) { @@ -449,7 +449,7 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) GET_TYPED_DATA(nd, double, pMemBucket->type, nextVal); double val = (1 - fraction) * td + fraction * nd; - tfree(buffer); + taosMemoryFreeClear(buffer); return val; } else { // incur a second round bucket split diff --git a/source/libs/function/src/tscript.c b/source/libs/function/src/tscript.c index 25cf3cfbb1..93e8ecf5cf 100644 --- a/source/libs/function/src/tscript.c +++ b/source/libs/function/src/tscript.c @@ -195,7 +195,7 @@ void taosLoadScriptDestroy(void *pInit) { } ScriptCtx* createScriptCtx(char *script, int8_t resType, int16_t resBytes) { - ScriptCtx *pCtx = (ScriptCtx *)calloc(1, sizeof(ScriptCtx)); + ScriptCtx *pCtx = (ScriptCtx *)taosMemoryCalloc(1, sizeof(ScriptCtx)); pCtx->state = SCRIPT_STATE_INIT; pCtx->pEnv = getScriptEnvFromPool(); // pCtx->resType = resType; @@ -229,7 +229,7 @@ ScriptCtx* createScriptCtx(char *script, int8_t resType, int16_t resBytes) { void destroyScriptCtx(void *pCtx) { if (pCtx == NULL) return; addScriptEnvToPool(((ScriptCtx *)pCtx)->pEnv); - free(pCtx); + taosMemoryFree(pCtx); } void luaValueToTaosType(lua_State *lua, char *interBuf, int32_t *numOfOutput, int16_t oType, int16_t oBytes) { @@ -332,12 +332,12 @@ void destroyLuaEnv(lua_State *lua) { int32_t scriptEnvPoolInit() { const int size = 10; // configure or not - pool = malloc(sizeof(ScriptEnvPool)); + pool = taosMemoryMalloc(sizeof(ScriptEnvPool)); taosThreadMutexInit(&pool->mutex, NULL); pool->scriptEnvs = tdListNew(sizeof(ScriptEnv *)); for (int i = 0; i < size; i++) { - ScriptEnv *env = malloc(sizeof(ScriptEnv)); + ScriptEnv *env = taosMemoryMalloc(sizeof(ScriptEnv)); env->funcId = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);; env->lua_state = createLuaEnv(); tdListAppend(pool->scriptEnvs, (void *)(&env)); @@ -360,13 +360,13 @@ void scriptEnvPoolCleanup() { } tdListFree(pool->scriptEnvs); taosThreadMutexDestroy(&pool->mutex); - free(pool); + taosMemoryFree(pool); } void destroyScriptEnv(ScriptEnv *pEnv) { destroyLuaEnv(pEnv->lua_state); taosHashCleanup(pEnv->funcId); - free(pEnv); + taosMemoryFree(pEnv); } ScriptEnv* getScriptEnvFromPool() { diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 6fcdb34529..a1030f6c21 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -195,7 +195,7 @@ int32_t encodeRequest(char **pBuf, int32_t *pBufLen, SUdfRequest *request) { break; } - char *bufBegin = malloc(len); + char *bufBegin = taosMemoryMalloc(len); char *buf = bufBegin; //skip msgLen first @@ -263,7 +263,7 @@ int32_t decodeRequest(char *bufMsg, int32_t bufLen, SUdfRequest **pRequest) { return -1; } char *buf = bufMsg; - SUdfRequest *request = malloc(sizeof(SUdfRequest)); + SUdfRequest *request = taosMemoryMalloc(sizeof(SUdfRequest)); request->subReq = NULL; request->msgLen = *(int32_t *) (buf); buf += sizeof(int32_t); @@ -274,7 +274,7 @@ int32_t decodeRequest(char *bufMsg, int32_t bufLen, SUdfRequest **pRequest) { switch (request->type) { case UDF_TASK_SETUP: { - SUdfSetupRequest *setup = malloc(sizeof(SUdfSetupRequest)); + SUdfSetupRequest *setup = taosMemoryMalloc(sizeof(SUdfSetupRequest)); memcpy(setup->udfName, buf, 16); buf += 16; @@ -291,7 +291,7 @@ int32_t decodeRequest(char *bufMsg, int32_t bufLen, SUdfRequest **pRequest) { break; } case UDF_TASK_CALL: { - SUdfCallRequest *call = malloc(sizeof(SUdfCallRequest)); + SUdfCallRequest *call = taosMemoryMalloc(sizeof(SUdfCallRequest)); call->udfHandle = *(int64_t *) buf; buf += sizeof(int64_t); @@ -311,7 +311,7 @@ int32_t decodeRequest(char *bufMsg, int32_t bufLen, SUdfRequest **pRequest) { } case UDF_TASK_TEARDOWN: { - SUdfTeardownRequest *teardown = malloc(sizeof(SUdfTeardownRequest)); + SUdfTeardownRequest *teardown = taosMemoryMalloc(sizeof(SUdfTeardownRequest)); teardown->udfHandle = *(int64_t *) buf; buf += sizeof(int64_t); @@ -322,8 +322,8 @@ int32_t decodeRequest(char *bufMsg, int32_t bufLen, SUdfRequest **pRequest) { } if (buf - bufMsg != bufLen) { debugPrint("%s", "decode request error"); - free(request->subReq); - free(request); + taosMemoryFree(request->subReq); + taosMemoryFree(request); return -1; } *pRequest = request; @@ -352,7 +352,7 @@ int32_t encodeResponse(char **pBuf, int32_t *pBufLen, SUdfResponse *response) { } } - char *bufBegin = malloc(len); + char *bufBegin = taosMemoryMalloc(len); char *buf = bufBegin; //skip msgLen @@ -408,7 +408,7 @@ int32_t decodeResponse(char *bufMsg, int32_t bufLen, SUdfResponse **pResponse) { return -1; } char *buf = bufMsg; - SUdfResponse *rsp = malloc(sizeof(SUdfResponse)); + SUdfResponse *rsp = taosMemoryMalloc(sizeof(SUdfResponse)); rsp->msgLen = *(int32_t *) buf; buf += sizeof(int32_t); rsp->seqNum = *(int64_t *) buf; @@ -420,14 +420,14 @@ int32_t decodeResponse(char *bufMsg, int32_t bufLen, SUdfResponse **pResponse) { switch (rsp->type) { case UDF_TASK_SETUP: { - SUdfSetupResponse *setupRsp = (SUdfSetupResponse *) malloc(sizeof(SUdfSetupResponse)); + SUdfSetupResponse *setupRsp = (SUdfSetupResponse *) taosMemoryMalloc(sizeof(SUdfSetupResponse)); setupRsp->udfHandle = *(int64_t *) buf; buf += sizeof(int64_t); rsp->subRsp = (char *) setupRsp; break; } case UDF_TASK_CALL: { - SUdfCallResponse *callRsp = (SUdfCallResponse *) malloc(sizeof(SUdfCallResponse)); + SUdfCallResponse *callRsp = (SUdfCallResponse *) taosMemoryMalloc(sizeof(SUdfCallResponse)); callRsp->outputBytes = *(int32_t *) buf; buf += sizeof(int32_t); @@ -444,7 +444,7 @@ int32_t decodeResponse(char *bufMsg, int32_t bufLen, SUdfResponse **pResponse) { break; } case UDF_TASK_TEARDOWN: { - SUdfTeardownResponse *teardownRsp = (SUdfTeardownResponse *) malloc(sizeof(SUdfTeardownResponse)); + SUdfTeardownResponse *teardownRsp = (SUdfTeardownResponse *) taosMemoryMalloc(sizeof(SUdfTeardownResponse)); rsp->subRsp = teardownRsp; break; } @@ -453,8 +453,8 @@ int32_t decodeResponse(char *bufMsg, int32_t bufLen, SUdfResponse **pResponse) { } if (buf - bufMsg != bufLen) { debugPrint("%s", "can not decode response"); - free(rsp->subRsp); - free(rsp); + taosMemoryFree(rsp->subRsp); + taosMemoryFree(rsp); return -1; } *pResponse = rsp; @@ -475,9 +475,9 @@ void onUdfcPipeClose(uv_handle_t *handle) { uv_sem_post(&task->taskSem); } - free(conn->readBuf.buf); - free(conn); - free((uv_pipe_t *) handle); + taosMemoryFree(conn->readBuf.buf); + taosMemoryFree(conn); + taosMemoryFree((uv_pipe_t *) handle); } @@ -511,9 +511,9 @@ int32_t udfcGetUvTaskResponseResult(SClientUdfTask *task, SClientUvTaskNode *uvT } // TODO: the call buffer is setup and freed by udf invocation - free(uvTask->rspBuf.base); - free(rsp->subRsp); - free(rsp); + taosMemoryFree(uvTask->rspBuf.base); + taosMemoryFree(rsp->subRsp); + taosMemoryFree(rsp); } else { task->errCode = uvTask->errCode; } @@ -532,7 +532,7 @@ void udfcAllocateBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf int32_t msgHeadSize = sizeof(int32_t) + sizeof(int64_t); if (connBuf->cap == 0) { - connBuf->buf = malloc(msgHeadSize); + connBuf->buf = taosMemoryMalloc(msgHeadSize); if (connBuf->buf) { connBuf->len = 0; connBuf->cap = msgHeadSize; @@ -547,7 +547,7 @@ void udfcAllocateBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf } } else { connBuf->cap = connBuf->total > connBuf->cap ? connBuf->total : connBuf->cap; - void *resultBuf = realloc(connBuf->buf, connBuf->cap); + void *resultBuf = taosMemoryRealloc(connBuf->buf, connBuf->cap); if (resultBuf) { connBuf->buf = resultBuf; buf->base = connBuf->buf + connBuf->len; @@ -648,8 +648,8 @@ void onUdfClientWrite(uv_write_t *write, int status) { //TODO Log error; } debugPrint("\tlength:%zu", uvTask->reqBuf.len); - free(write); - free(uvTask->reqBuf.base); + taosMemoryFree(write); + taosMemoryFree(uvTask->reqBuf.base); } void onUdfClientConnect(uv_connect_t *connect, int status) { @@ -659,12 +659,12 @@ void onUdfClientConnect(uv_connect_t *connect, int status) { //TODO: LOG error } uv_read_start((uv_stream_t *) uvTask->pipe, udfcAllocateBuffer, onUdfcRead); - free(connect); + taosMemoryFree(connect); uv_sem_post(&uvTask->taskSem); } int32_t createUdfcUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvTaskNode **pUvTask) { - SClientUvTaskNode *uvTask = calloc(1, sizeof(SClientUvTaskNode)); + SClientUvTaskNode *uvTask = taosMemoryCalloc(1, sizeof(SClientUvTaskNode)); uvTask->type = uvTaskType; if (uvTaskType == UV_TASK_CONNECT) { @@ -718,11 +718,11 @@ int32_t startUvUdfTask(SClientUvTaskNode *uvTask) { debugPrint("%s, type %d", "start uv task ", uvTask->type); switch (uvTask->type) { case UV_TASK_CONNECT: { - uv_pipe_t *pipe = malloc(sizeof(uv_pipe_t)); + uv_pipe_t *pipe = taosMemoryMalloc(sizeof(uv_pipe_t)); uv_pipe_init(&gUdfdLoop, pipe, 0); uvTask->pipe = pipe; - SClientUvConn *conn = malloc(sizeof(SClientUvConn)); + SClientUvConn *conn = taosMemoryMalloc(sizeof(SClientUvConn)); conn->pipe = pipe; conn->readBuf.len = 0; conn->readBuf.cap = 0; @@ -732,7 +732,7 @@ int32_t startUvUdfTask(SClientUvTaskNode *uvTask) { pipe->data = conn; - uv_connect_t *connReq = malloc(sizeof(uv_connect_t)); + uv_connect_t *connReq = taosMemoryMalloc(sizeof(uv_connect_t)); connReq->data = uvTask; uv_pipe_connect(connReq, pipe, "udf.sock", onUdfClientConnect); @@ -740,7 +740,7 @@ int32_t startUvUdfTask(SClientUvTaskNode *uvTask) { } case UV_TASK_REQ_RSP: { uv_pipe_t *pipe = uvTask->pipe; - uv_write_t *write = malloc(sizeof(uv_write_t)); + uv_write_t *write = taosMemoryMalloc(sizeof(uv_write_t)); write->data = uvTask; uv_write(write, (uv_stream_t *) pipe, &uvTask->reqBuf, 1, onUdfClientWrite); break; @@ -833,16 +833,16 @@ int32_t udfcRunUvTask(SClientUdfTask *task, int8_t uvTaskType) { if (uvTaskType == UV_TASK_CONNECT) { task->session->udfSvcPipe = uvTask->pipe; } - free(uvTask); + taosMemoryFree(uvTask); uvTask = NULL; return task->errCode; } int32_t setupUdf(SUdfInfo *udfInfo, UdfHandle *handle) { debugPrint("%s", "client setup udf"); - SClientUdfTask *task = malloc(sizeof(SClientUdfTask)); + SClientUdfTask *task = taosMemoryMalloc(sizeof(SClientUdfTask)); task->errCode = 0; - task->session = malloc(sizeof(SUdfUvSession)); + task->session = taosMemoryMalloc(sizeof(SUdfUvSession)); task->type = UDF_TASK_SETUP; SUdfSetupRequest *req = &task->_setup.req; @@ -864,7 +864,7 @@ int32_t setupUdf(SUdfInfo *udfInfo, UdfHandle *handle) { task->session->severHandle = rsp->udfHandle; *handle = task->session; int32_t err = task->errCode; - free(task); + taosMemoryFree(task); return err; } @@ -872,7 +872,7 @@ int32_t callUdf(UdfHandle handle, int8_t step, char *state, int32_t stateSize, S int32_t *newStateSize, SUdfDataBlock *output) { debugPrint("%s", "client call udf"); - SClientUdfTask *task = malloc(sizeof(SClientUdfTask)); + SClientUdfTask *task = taosMemoryMalloc(sizeof(SClientUdfTask)); task->errCode = 0; task->session = (SUdfUvSession *) handle; task->type = UDF_TASK_CALL; @@ -894,14 +894,14 @@ int32_t callUdf(UdfHandle handle, int8_t step, char *state, int32_t stateSize, S output->size = rsp->outputBytes; output->data = rsp->output; int32_t err = task->errCode; - free(task); + taosMemoryFree(task); return err; } int32_t teardownUdf(UdfHandle handle) { debugPrint("%s", "client teardown udf"); - SClientUdfTask *task = malloc(sizeof(SClientUdfTask)); + SClientUdfTask *task = taosMemoryMalloc(sizeof(SClientUdfTask)); task->errCode = 0; task->session = (SUdfUvSession *) handle; task->type = UDF_TASK_TEARDOWN; @@ -918,8 +918,8 @@ int32_t teardownUdf(UdfHandle handle) { udfcRunUvTask(task, UV_TASK_DISCONNECT); - free(task->session); - free(task); + taosMemoryFree(task->session); + taosMemoryFree(task); return err; } diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 27385325f5..b473f060c0 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -62,7 +62,7 @@ void udfdProcessRequest(uv_work_t *req) { switch (request->type) { case UDF_TASK_SETUP: { debugPrint("%s", "process setup request"); - SUdf *udf = malloc(sizeof(SUdf)); + SUdf *udf = taosMemoryMalloc(sizeof(SUdf)); udf->refCount = 0; SUdfSetupRequest *setup = request->subReq; strcpy(udf->name, setup->udfName); @@ -78,15 +78,15 @@ void udfdProcessRequest(uv_work_t *req) { //TODO find all functions normal, init, destroy, normal, merge, finalize uv_dlsym(&udf->lib, normalFuncName, (void **) (&udf->normalFunc)); - SUdfHandle *handle = malloc(sizeof(SUdfHandle)); + SUdfHandle *handle = taosMemoryMalloc(sizeof(SUdfHandle)); handle->udf = udf; udf->refCount++; //TODO: allocate private structure and call init function and set it to handle - SUdfResponse *rsp = malloc(sizeof(SUdfResponse)); + SUdfResponse *rsp = taosMemoryMalloc(sizeof(SUdfResponse)); rsp->seqNum = request->seqNum; rsp->type = request->type; rsp->code = 0; - SUdfSetupResponse *subRsp = malloc(sizeof(SUdfSetupResponse)); + SUdfSetupResponse *subRsp = taosMemoryMalloc(sizeof(SUdfSetupResponse)); subRsp->udfHandle = (int64_t) (handle); rsp->subRsp = subRsp; char *buf; @@ -95,11 +95,11 @@ void udfdProcessRequest(uv_work_t *req) { uvUdf->output = uv_buf_init(buf, len); - free(rsp->subRsp); - free(rsp); - free(request->subReq); - free(request); - free(uvUdf->input.base); + taosMemoryFree(rsp->subRsp); + taosMemoryFree(rsp); + taosMemoryFree(request->subReq); + taosMemoryFree(request); + taosMemoryFree(uvUdf->input.base); break; } @@ -115,11 +115,11 @@ void udfdProcessRequest(uv_work_t *req) { //TODO: call different functions according to the step udf->normalFunc(call->step, call->state, call->stateBytes, input, &newState, &newStateSize, &output); - SUdfResponse *rsp = malloc(sizeof(SUdfResponse)); + SUdfResponse *rsp = taosMemoryMalloc(sizeof(SUdfResponse)); rsp->seqNum = request->seqNum; rsp->type = request->type; rsp->code = 0; - SUdfCallResponse *subRsp = malloc(sizeof(SUdfCallResponse)); + SUdfCallResponse *subRsp = taosMemoryMalloc(sizeof(SUdfCallResponse)); subRsp->outputBytes = output.size; subRsp->output = output.data; subRsp->newStateBytes = newStateSize; @@ -131,13 +131,13 @@ void udfdProcessRequest(uv_work_t *req) { encodeResponse(&buf, &len, rsp); uvUdf->output = uv_buf_init(buf, len); - free(rsp->subRsp); - free(rsp); - free(newState); - free(output.data); - free(request->subReq); - free(request); - free(uvUdf->input.base); + taosMemoryFree(rsp->subRsp); + taosMemoryFree(rsp); + taosMemoryFree(newState); + taosMemoryFree(output.data); + taosMemoryFree(request->subReq); + taosMemoryFree(request); + taosMemoryFree(uvUdf->input.base); break; } case UDF_TASK_TEARDOWN: { @@ -150,26 +150,26 @@ void udfdProcessRequest(uv_work_t *req) { if (udf->refCount == 0) { uv_dlclose(&udf->lib); } - free(udf); + taosMemoryFree(udf); //TODO: call destroy and free udf private - free(handle); + taosMemoryFree(handle); - SUdfResponse *rsp = malloc(sizeof(SUdfResponse)); + SUdfResponse *rsp = taosMemoryMalloc(sizeof(SUdfResponse)); rsp->seqNum = request->seqNum; rsp->type = request->type; rsp->code = 0; - SUdfTeardownResponse *subRsp = malloc(sizeof(SUdfTeardownResponse)); + SUdfTeardownResponse *subRsp = taosMemoryMalloc(sizeof(SUdfTeardownResponse)); rsp->subRsp = subRsp; char *buf; int32_t len; encodeResponse(&buf, &len, rsp); uvUdf->output = uv_buf_init(buf, len); - free(rsp->subRsp); - free(rsp); - free(request->subReq); - free(request); - free(uvUdf->input.base); + taosMemoryFree(rsp->subRsp); + taosMemoryFree(rsp); + taosMemoryFree(request->subReq); + taosMemoryFree(request); + taosMemoryFree(uvUdf->input.base); break; } default: { @@ -187,9 +187,9 @@ void udfdOnWrite(uv_write_t *req, int status) { } SUvUdfWork *work = (SUvUdfWork *) req->data; debugPrint("\tlength: %zu", work->output.len); - free(work->output.base); - free(work); - free(req); + taosMemoryFree(work->output.base); + taosMemoryFree(work); + taosMemoryFree(req); } @@ -197,11 +197,11 @@ void udfdSendResponse(uv_work_t *work, int status) { debugPrint("%s", "send response"); SUvUdfWork *udfWork = (SUvUdfWork *) (work->data); - uv_write_t *write_req = malloc(sizeof(uv_write_t)); + uv_write_t *write_req = taosMemoryMalloc(sizeof(uv_write_t)); write_req->data = udfWork; uv_write(write_req, udfWork->client, &udfWork->output, 1, udfdOnWrite); - free(work); + taosMemoryFree(work); } void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) { @@ -209,7 +209,7 @@ void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) { SUdfdUvConn *ctx = handle->data; int32_t msgHeadSize = sizeof(int32_t) + sizeof(int64_t); if (ctx->inputCap == 0) { - ctx->inputBuf = malloc(msgHeadSize); + ctx->inputBuf = taosMemoryMalloc(msgHeadSize); if (ctx->inputBuf) { ctx->inputLen = 0; ctx->inputCap = msgHeadSize; @@ -224,7 +224,7 @@ void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) { } } else { ctx->inputCap = ctx->inputTotal > ctx->inputCap ? ctx->inputTotal : ctx->inputCap; - void *inputBuf = realloc(ctx->inputBuf, ctx->inputCap); + void *inputBuf = taosMemoryRealloc(ctx->inputBuf, ctx->inputCap); if (inputBuf) { ctx->inputBuf = inputBuf; buf->base = ctx->inputBuf + ctx->inputLen; @@ -250,8 +250,8 @@ bool isUdfdUvMsgComplete(SUdfdUvConn *pipe) { } void udfdHandleRequest(SUdfdUvConn *conn) { - uv_work_t *work = malloc(sizeof(uv_work_t)); - SUvUdfWork *udfWork = malloc(sizeof(SUvUdfWork)); + uv_work_t *work = taosMemoryMalloc(sizeof(uv_work_t)); + SUvUdfWork *udfWork = taosMemoryMalloc(sizeof(SUvUdfWork)); udfWork->client = conn->client; udfWork->input = uv_buf_init(conn->inputBuf, conn->inputLen); conn->inputBuf = NULL; @@ -264,9 +264,9 @@ void udfdHandleRequest(SUdfdUvConn *conn) { void udfdPipeCloseCb(uv_handle_t *pipe) { SUdfdUvConn *conn = pipe->data; - free(conn->client); - free(conn->inputBuf); - free(conn); + taosMemoryFree(conn->client); + taosMemoryFree(conn->inputBuf); + taosMemoryFree(conn); } void udfdUvHandleError(SUdfdUvConn *conn) { @@ -307,10 +307,10 @@ void udfdOnNewConnection(uv_stream_t *server, int status) { return; } - uv_pipe_t *client = (uv_pipe_t *) malloc(sizeof(uv_pipe_t)); + uv_pipe_t *client = (uv_pipe_t *) taosMemoryMalloc(sizeof(uv_pipe_t)); uv_pipe_init(loop, client, 0); if (uv_accept(server, (uv_stream_t *) client) == 0) { - SUdfdUvConn *ctx = malloc(sizeof(SUdfdUvConn)); + SUdfdUvConn *ctx = taosMemoryMalloc(sizeof(SUdfdUvConn)); ctx->client = (uv_stream_t *) client; ctx->inputBuf = 0; ctx->inputLen = 0; diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index b7d651e55e..bd742d23d0 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -3,6 +3,7 @@ #include #include "uv.h" +#include "os.h" #include "tudf.h" int main(int argc, char *argv[]) { @@ -28,8 +29,8 @@ int main(int argc, char *argv[]) { int callCount = 2; if (argc > 1) dataSize = atoi(argv[1]); if (argc > 2) callCount = atoi(argv[2]); - char *state = malloc(dataSize); - char *input = malloc(dataSize); + char *state = taosMemoryMalloc(dataSize); + char *input = taosMemoryMalloc(dataSize); SUdfDataBlock blockInput = {.data = input, .size = dataSize}; SUdfDataBlock blockOutput; char* newState; @@ -37,8 +38,8 @@ int main(int argc, char *argv[]) { for (int l = 0; l < callCount; ++l) { callUdf(handle, 0, state, dataSize, blockInput, &newState, &newStateSize, &blockOutput); } - free(state); - free(input); + taosMemoryFree(state); + taosMemoryFree(input); teardownUdf(handle); stopUdfService(); diff --git a/source/libs/function/test/udf1.c b/source/libs/function/test/udf1.c index 15e96e3bd1..dc88e8cf3e 100644 --- a/source/libs/function/test/udf1.c +++ b/source/libs/function/test/udf1.c @@ -2,17 +2,18 @@ #include #include +#include "os.h" #include "tudf.h" void udf1(int8_t step, char *state, int32_t stateSize, SUdfDataBlock input, char **newState, int32_t *newStateSize, SUdfDataBlock *output) { fprintf(stdout, "%s, step:%d\n", "udf function called", step); - char *newStateBuf = malloc(stateSize); + char *newStateBuf = taosMemoryMalloc(stateSize); memcpy(newStateBuf, state, stateSize); *newState = newStateBuf; *newStateSize = stateSize; - char *outputBuf = malloc(input.size); + char *outputBuf = taosMemoryMalloc(input.size); memcpy(outputBuf, input.data, input.size); output->data = outputBuf; output->size = input.size; diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 83410306eb..61dd952381 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -62,7 +62,7 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* icache, Iterat int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { taosThreadOnce(&isInit, indexInit); - SIndex* sIdx = calloc(1, sizeof(SIndex)); + SIndex* sIdx = taosMemoryCalloc(1, sizeof(SIndex)); if (sIdx == NULL) { return -1; } @@ -115,8 +115,8 @@ void indexClose(SIndex* sIdx) { taosThreadMutexDestroy(&sIdx->mtx); indexTFileDestroy(sIdx->tindex); #endif - free(sIdx->path); - free(sIdx); + taosMemoryFree(sIdx->path); + taosMemoryFree(sIdx); return; } @@ -179,16 +179,16 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result EIndexOperatorType opera = multiQuerys->opera; int nQuery = taosArrayGetSize(multiQuerys->query); - char** fields = malloc(sizeof(char*) * nQuery); - char** keys = malloc(sizeof(char*) * nQuery); - int* types = malloc(sizeof(int) * nQuery); + char** fields = taosMemoryMalloc(sizeof(char*) * nQuery); + char** keys = taosMemoryMalloc(sizeof(char*) * nQuery); + int* types = taosMemoryMalloc(sizeof(int) * nQuery); for (int i = 0; i < nQuery; i++) { SIndexTermQuery* p = taosArrayGet(multiQuerys->query, i); SIndexTerm* term = p->field_value; - fields[i] = calloc(1, term->nKey + 1); - keys[i] = calloc(1, term->nVal + 1); + fields[i] = taosMemoryCalloc(1, term->nKey + 1); + keys[i] = taosMemoryCalloc(1, term->nVal + 1); memcpy(fields[i], term->key, term->nKey); memcpy(keys[i], term->val, term->nVal); @@ -203,12 +203,12 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result } for (int i = 0; i < nQuery; i++) { - free(fields[i]); - free(keys[i]); + taosMemoryFree(fields[i]); + taosMemoryFree(keys[i]); } - free(fields); - free(keys); - free(types); + taosMemoryFree(fields); + taosMemoryFree(keys); + taosMemoryFree(types); #endif #ifdef USE_INVERTED_INDEX @@ -258,7 +258,7 @@ void indexOptsDestroy(SIndexOpts* opts) { * */ SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType opera) { - SIndexMultiTermQuery* p = (SIndexMultiTermQuery*)malloc(sizeof(SIndexMultiTermQuery)); + SIndexMultiTermQuery* p = (SIndexMultiTermQuery*)taosMemoryMalloc(sizeof(SIndexMultiTermQuery)); if (p == NULL) { return NULL; } @@ -272,7 +272,7 @@ void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery) { indexTermDestroy(p->term); } taosArrayDestroy(pQuery->query); - free(pQuery); + taosMemoryFree(pQuery); }; int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType qType) { SIndexTermQuery q = {.qType = qType, .term = term}; @@ -282,7 +282,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colType, const char* colName, int32_t nColName, const char* colVal, int32_t nColVal) { - SIndexTerm* t = (SIndexTerm*)calloc(1, (sizeof(SIndexTerm))); + SIndexTerm* t = (SIndexTerm*)taosMemoryCalloc(1, (sizeof(SIndexTerm))); if (t == NULL) { return NULL; } @@ -291,19 +291,19 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy t->operType = oper; t->colType = colType; - t->colName = (char*)calloc(1, nColName + 1); + t->colName = (char*)taosMemoryCalloc(1, nColName + 1); memcpy(t->colName, colName, nColName); t->nColName = nColName; - t->colVal = (char*)calloc(1, nColVal + 1); + t->colVal = (char*)taosMemoryCalloc(1, nColVal + 1); memcpy(t->colVal, colVal, nColVal); t->nColVal = nColVal; return t; } void indexTermDestroy(SIndexTerm* p) { - free(p->colName); - free(p->colVal); - free(p); + taosMemoryFree(p->colName); + taosMemoryFree(p->colVal); + taosMemoryFree(p); } SIndexMultiTerm* indexMultiTermCreate() { return taosArrayInit(4, sizeof(SIndexTerm*)); } @@ -536,7 +536,7 @@ void iterateValueDestroy(IterateValue* value, bool destroy) { taosArrayClear(value->val); } } - free(value->colVal); + taosMemoryFree(value->colVal); value->colVal = NULL; } static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { @@ -572,7 +572,7 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { END: if (tw != NULL) { writerCtxDestroy(tw->ctx, true); - free(tw); + taosMemoryFree(tw); } return -1; } diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index 2b4327b091..bf907726bc 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -40,7 +40,7 @@ static bool indexCacheIteratorNext(Iterate* itera); static IterateValue* indexCacheIteratorGetValue(Iterate* iter); IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type) { - IndexCache* cache = calloc(1, sizeof(IndexCache)); + IndexCache* cache = taosMemoryCalloc(1, sizeof(IndexCache)); if (cache == NULL) { indexError("failed to create index cache"); return NULL; @@ -113,8 +113,8 @@ void indexCacheDestroySkiplist(SSkipList* slt) { SSkipListNode* node = tSkipListIterGet(iter); CacheTerm* ct = (CacheTerm*)SL_GET_NODE_DATA(node); if (ct != NULL) { - free(ct->colVal); - free(ct); + taosMemoryFree(ct->colVal); + taosMemoryFree(ct); } } tSkipListDestroyIter(iter); @@ -144,16 +144,16 @@ void indexCacheDestroy(void* cache) { } indexMemUnRef(pCache->mem); indexMemUnRef(pCache->imm); - free(pCache->colName); + taosMemoryFree(pCache->colName); taosThreadMutexDestroy(&pCache->mtx); taosThreadCondDestroy(&pCache->finished); - free(pCache); + taosMemoryFree(pCache); } Iterate* indexCacheIteratorCreate(IndexCache* cache) { - Iterate* iiter = calloc(1, sizeof(Iterate)); + Iterate* iiter = taosMemoryCalloc(1, sizeof(Iterate)); if (iiter == NULL) { return NULL; } @@ -179,7 +179,7 @@ void indexCacheIteratorDestroy(Iterate* iter) { } tSkipListDestroyIter(iter->iter); iterateValueDestroy(&iter->val, true); - free(iter); + taosMemoryFree(iter); } int indexCacheSchedToMerge(IndexCache* pCache) { @@ -221,7 +221,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) { IndexCache* pCache = cache; indexCacheRef(pCache); // encode data - CacheTerm* ct = calloc(1, sizeof(CacheTerm)); + CacheTerm* ct = taosMemoryCalloc(1, sizeof(CacheTerm)); if (cache == NULL) { return -1; } @@ -230,7 +230,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) { if (hasJson) { ct->colVal = indexPackJsonData(term); } else { - ct->colVal = (char*)calloc(1, sizeof(char) * (term->nColVal + 1)); + ct->colVal = (char*)taosMemoryCalloc(1, sizeof(char) * (term->nColVal + 1)); memcpy(ct->colVal, term->colVal, term->nColVal); } ct->version = atomic_add_fetch_32(&pCache->version, 1); @@ -323,7 +323,7 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result } if (hasJson) { - tfree(p); + taosMemoryFreeClear(p); } indexMemUnRef(mem); @@ -365,7 +365,7 @@ void indexMemUnRef(MemTable* tbl) { if (ref == 0) { SSkipList* slt = tbl->mem; indexCacheDestroySkiplist(slt); - free(tbl); + taosMemoryFree(tbl); } } @@ -373,8 +373,8 @@ static void indexCacheTermDestroy(CacheTerm* ct) { if (ct == NULL) { return; } - free(ct->colVal); - free(ct); + taosMemoryFree(ct->colVal); + taosMemoryFree(ct); } static char* indexCacheTermGet(const void* pData) { CacheTerm* p = (CacheTerm*)pData; @@ -394,7 +394,7 @@ static int32_t indexCacheTermCompare(const void* l, const void* r) { static MemTable* indexInternalCacheCreate(int8_t type) { type = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? TSDB_DATA_TYPE_BINARY : type; - MemTable* tbl = calloc(1, sizeof(MemTable)); + MemTable* tbl = taosMemoryCalloc(1, sizeof(MemTable)); indexMemRef(tbl); if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { tbl->mem = tSkipListCreate(MAX_SKIP_LIST_LEVEL, type, MAX_INDEX_KEY_LEN, indexCacheTermCompare, SL_ALLOW_DUP_KEY, diff --git a/source/libs/index/src/index_comm.c b/source/libs/index/src/index_comm.c index 4f3cbaa4da..4dea5fa011 100644 --- a/source/libs/index/src/index_comm.c +++ b/source/libs/index/src/index_comm.c @@ -27,7 +27,7 @@ char* indexPackJsonData(SIndexTerm* itm) { uint8_t ty = INDEX_TYPE_GET_TYPE(itm->colType); int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1; - char* buf = (char*)calloc(1, sz); + char* buf = (char*)taosMemoryCalloc(1, sz); char* p = buf; memcpy(p, itm->colName, itm->nColName); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 58d5a871cd..09f382bbdc 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -30,7 +30,7 @@ static uint8_t fstPackDetla(FstCountingWriter* wrt, CompiledAddr nodeAddr, Compi } FstUnFinishedNodes* fstUnFinishedNodesCreate() { - FstUnFinishedNodes* nodes = malloc(sizeof(FstUnFinishedNodes)); + FstUnFinishedNodes* nodes = taosMemoryMalloc(sizeof(FstUnFinishedNodes)); if (nodes == NULL) { return NULL; } @@ -42,7 +42,7 @@ FstUnFinishedNodes* fstUnFinishedNodesCreate() { static void unFinishedNodeDestroyElem(void* elem) { FstBuilderNodeUnfinished* b = (FstBuilderNodeUnfinished*)elem; fstBuilderNodeDestroy(b->node); - free(b->last); + taosMemoryFree(b->last); b->last = NULL; } void fstUnFinishedNodesDestroy(FstUnFinishedNodes* nodes) { @@ -51,11 +51,11 @@ void fstUnFinishedNodesDestroy(FstUnFinishedNodes* nodes) { } taosArrayDestroyEx(nodes->stack, unFinishedNodeDestroyElem); - free(nodes); + taosMemoryFree(nodes); } void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes* nodes, bool isFinal) { - FstBuilderNode* node = malloc(sizeof(FstBuilderNode)); + FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode)); node->isFinal = isFinal; node->finalOutput = 0; node->trans = taosArrayInit(16, sizeof(FstTransition)); @@ -74,7 +74,7 @@ FstBuilderNode* fstUnFinishedNodesPopRoot(FstUnFinishedNodes* nodes) { FstBuilderNode* fstUnFinishedNodesPopFreeze(FstUnFinishedNodes* nodes, CompiledAddr addr) { FstBuilderNodeUnfinished* un = taosArrayPop(nodes->stack); fstBuilderNodeUnfinishedLastCompiled(un, addr); - // free(un->last); // TODO add func FstLastTransitionFree() + // taosMemoryFree(un->last); // TODO add func FstLastTransitionFree() // un->last = NULL; return un->node; } @@ -103,7 +103,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output FstBuilderNodeUnfinished* un = taosArrayGet(nodes->stack, sz); assert(un->last == NULL); - // FstLastTransition *trn = malloc(sizeof(FstLastTransition)); + // FstLastTransition *trn = taosMemoryMalloc(sizeof(FstLastTransition)); // trn->inp = s->data[s->start]; // trn->out = out; int32_t len = 0; @@ -111,12 +111,12 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output un->last = fstLastTransitionCreate(data[0], out); for (uint64_t i = 1; i < len; i++) { - FstBuilderNode* n = malloc(sizeof(FstBuilderNode)); + FstBuilderNode* n = taosMemoryMalloc(sizeof(FstBuilderNode)); n->isFinal = false; n->finalOutput = 0; n->trans = taosArrayInit(16, sizeof(FstTransition)); - // FstLastTransition *trn = malloc(sizeof(FstLastTransition)); + // FstLastTransition *trn = taosMemoryMalloc(sizeof(FstLastTransition)); // trn->inp = s->data[i]; // trn->out = out; FstLastTransition* trn = fstLastTransitionCreate(data[i], 0); @@ -296,7 +296,7 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil // at that index. (Except when there are 256 transitions.) Namely, // any value greater than or equal to the number of transitions in // this node indicates an absent transition. - uint8_t* index = (uint8_t*)malloc(sizeof(uint8_t) * 256); + uint8_t* index = (uint8_t*)taosMemoryMalloc(sizeof(uint8_t) * 256); memset(index, 255, sizeof(uint8_t) * 256); /// for (uint8_t i = 0; i < 256; i++) { // index[i] = 255; @@ -307,7 +307,7 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil // fstPackDeltaIn(w, addr, t->addr, tSize); } fstCountingWriterWrite(w, (char*)index, 256); - free(index); + taosMemoryFree(index); } fstCountingWriterWrite(w, (char*)&packSizes, 1); bool null = false; @@ -578,7 +578,7 @@ uint64_t fstStateFindInput(FstState* s, FstNode* node, uint8_t b, bool* null) { // fst node function FstNode* fstNodeCreate(int64_t version, CompiledAddr addr, FstSlice* slice) { - FstNode* n = (FstNode*)malloc(sizeof(FstNode)); + FstNode* n = (FstNode*)taosMemoryMalloc(sizeof(FstNode)); if (n == NULL) { return NULL; } @@ -643,10 +643,10 @@ static const char* fstNodeState(FstNode* node) { void fstNodeDestroy(FstNode* node) { fstSliceDestroy(&node->data); - free(node); + taosMemoryFree(node); } FstTransitions* fstNodeTransitions(FstNode* node) { - FstTransitions* t = malloc(sizeof(FstTransitions)); + FstTransitions* t = taosMemoryMalloc(sizeof(FstTransitions)); if (NULL == t) { return NULL; } @@ -755,7 +755,7 @@ bool fstBuilderNodeCompileTo(FstBuilderNode* b, FstCountingWriter* wrt, Compiled } FstBuilder* fstBuilderCreate(void* w, FstType ty) { - FstBuilder* b = malloc(sizeof(FstBuilder)); + FstBuilder* b = taosMemoryMalloc(sizeof(FstBuilder)); if (NULL == b) { return b; } @@ -788,7 +788,7 @@ void fstBuilderDestroy(FstBuilder* b) { fstUnFinishedNodesDestroy(b->unfinished); fstRegistryDestroy(b->registry); fstSliceDestroy(&b->last); - free(b); + taosMemoryFree(b); } bool fstBuilderInsert(FstBuilder* b, FstSlice bs, Output in) { @@ -928,7 +928,7 @@ FstSlice fstNodeAsSlice(FstNode* node) { } FstLastTransition* fstLastTransitionCreate(uint8_t inp, Output out) { - FstLastTransition* trn = malloc(sizeof(FstLastTransition)); + FstLastTransition* trn = taosMemoryMalloc(sizeof(FstLastTransition)); if (trn == NULL) { return NULL; } @@ -938,7 +938,7 @@ FstLastTransition* fstLastTransitionCreate(uint8_t inp, Output out) { return trn; } -void fstLastTransitionDestroy(FstLastTransition* trn) { free(trn); } +void fstLastTransitionDestroy(FstLastTransition* trn) { taosMemoryFree(trn); } void fstBuilderNodeUnfinishedLastCompiled(FstBuilderNodeUnfinished* unNode, CompiledAddr addr) { FstLastTransition* trn = unNode->last; @@ -1003,12 +1003,12 @@ Fst* fstCreate(FstSlice* slice) { len -= sizeof(fstLen); taosDecodeFixedU64(buf + len, &fstLen); // TODO(validate root addr) - Fst* fst = (Fst*)calloc(1, sizeof(Fst)); + Fst* fst = (Fst*)taosMemoryCalloc(1, sizeof(Fst)); if (fst == NULL) { return NULL; } - fst->meta = (FstMeta*)malloc(sizeof(FstMeta)); + fst->meta = (FstMeta*)taosMemoryMalloc(sizeof(FstMeta)); if (NULL == fst->meta) { goto FST_CREAT_FAILED; } @@ -1019,7 +1019,7 @@ Fst* fstCreate(FstSlice* slice) { fst->meta->len = fstLen; fst->meta->checkSum = checkSum; - FstSlice* s = calloc(1, sizeof(FstSlice)); + FstSlice* s = taosMemoryCalloc(1, sizeof(FstSlice)); *s = fstSliceCopy(slice, 0, FST_SLICE_LEN(slice) - 1); fst->data = s; @@ -1027,19 +1027,19 @@ Fst* fstCreate(FstSlice* slice) { return fst; FST_CREAT_FAILED: - free(fst->meta); - free(fst); + taosMemoryFree(fst->meta); + taosMemoryFree(fst); return NULL; } void fstDestroy(Fst* fst) { if (fst) { - free(fst->meta); + taosMemoryFree(fst->meta); fstSliceDestroy(fst->data); - free(fst->data); + taosMemoryFree(fst->data); taosThreadMutexDestroy(&fst->mtx); } - free(fst); + taosMemoryFree(fst); } bool fstGet(Fst* fst, FstSlice* b, Output* out) { @@ -1136,7 +1136,7 @@ bool fstVerify(Fst* fst) { // data bound function FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice* data) { - FstBoundWithData* b = calloc(1, sizeof(FstBoundWithData)); + FstBoundWithData* b = taosMemoryCalloc(1, sizeof(FstBoundWithData)); if (b == NULL) { return NULL; } @@ -1171,11 +1171,11 @@ bool fstBoundWithDataIsEmpty(FstBoundWithData* bound) { bool fstBoundWithDataIsIncluded(FstBoundWithData* bound) { return bound->type == Excluded ? false : true; } -void fstBoundDestroy(FstBoundWithData* bound) { free(bound); } +void fstBoundDestroy(FstBoundWithData* bound) { taosMemoryFree(bound); } StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstBoundWithData* min, FstBoundWithData* max) { - StreamWithState* sws = calloc(1, sizeof(StreamWithState)); + StreamWithState* sws = taosMemoryCalloc(1, sizeof(StreamWithState)); if (sws == NULL) { return NULL; } @@ -1201,7 +1201,7 @@ void streamWithStateDestroy(StreamWithState* sws) { taosArrayDestroy(sws->inp); taosArrayDestroyEx(sws->stack, streamStateDestroy); - free(sws); + taosMemoryFree(sws); } bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) { @@ -1346,7 +1346,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb taosArrayPush(sws->stack, &s2); size_t isz = taosArrayGetSize(sws->inp); - uint8_t* buf = (uint8_t*)malloc(isz * sizeof(uint8_t)); + uint8_t* buf = (uint8_t*)taosMemoryMalloc(isz * sizeof(uint8_t)); for (uint32_t i = 0; i < isz; i++) { buf[i] = *(uint8_t*)taosArrayGet(sws->inp, i); } @@ -1354,19 +1354,19 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb if (fstBoundWithDataExceededBy(sws->endAt, &slice)) { taosArrayDestroyEx(sws->stack, streamStateDestroy); sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); - tfree(buf); + taosMemoryFreeClear(buf); fstSliceDestroy(&slice); return NULL; } if (FST_NODE_IS_FINAL(nextNode) && isMatch) { FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)}; StreamWithStateResult* result = swsResultCreate(&slice, fOutput, tState); - tfree(buf); + taosMemoryFreeClear(buf); fstSliceDestroy(&slice); taosArrayDestroy(nodes); return result; } - tfree(buf); + taosMemoryFreeClear(buf); fstSliceDestroy(&slice); } for (size_t i = 0; i < taosArrayGetSize(nodes); i++) { @@ -1378,7 +1378,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb } StreamWithStateResult* swsResultCreate(FstSlice* data, FstOutput fOut, void* state) { - StreamWithStateResult* result = calloc(1, sizeof(StreamWithStateResult)); + StreamWithStateResult* result = taosMemoryCalloc(1, sizeof(StreamWithStateResult)); if (result == NULL) { return NULL; } @@ -1395,7 +1395,7 @@ void swsResultDestroy(StreamWithStateResult* result) { fstSliceDestroy(&result->data); startWithStateValueDestroy(result->state); - free(result); + taosMemoryFree(result); } void streamStateDestroy(void* s) { @@ -1407,7 +1407,7 @@ void streamStateDestroy(void* s) { } FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut) { - FstStreamBuilder* b = calloc(1, sizeof(FstStreamBuilder)); + FstStreamBuilder* b = taosMemoryCalloc(1, sizeof(FstStreamBuilder)); if (NULL == b) { return NULL; } @@ -1421,9 +1421,9 @@ FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut) { void fstStreamBuilderDestroy(FstStreamBuilder* b) { fstSliceDestroy(&b->min->data); fstSliceDestroy(&b->max->data); - tfree(b->min); - tfree(b->max); - free(b); + taosMemoryFreeClear(b->min); + taosMemoryFreeClear(b->max); + taosMemoryFree(b); } FstStreamBuilder* fstStreamBuilderRange(FstStreamBuilder* b, FstSlice* val, RangeType type) { if (b == NULL) { diff --git a/source/libs/index/src/index_fst_automation.c b/source/libs/index/src/index_fst_automation.c index ed1ad7a374..668a527d4a 100644 --- a/source/libs/index/src/index_fst_automation.c +++ b/source/libs/index/src/index_fst_automation.c @@ -16,7 +16,7 @@ #include "index_fst_automation.h" StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void* val) { - StartWithStateValue* sv = calloc(1, sizeof(StartWithStateValue)); + StartWithStateValue* sv = taosMemoryCalloc(1, sizeof(StartWithStateValue)); if (sv == NULL) { return NULL; } @@ -27,7 +27,7 @@ StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueTyp sv->val = *(int*)val; } else if (ty == FST_CHAR) { size_t len = strlen((char*)val); - sv->ptr = (char*)calloc(1, len + 1); + sv->ptr = (char*)taosMemoryCalloc(1, len + 1); memcpy(sv->ptr, val, len); } else if (ty == FST_ARRAY) { // TODO, @@ -44,14 +44,14 @@ void startWithStateValueDestroy(void* val) { if (sv->type == FST_INT) { // } else if (sv->type == FST_CHAR) { - free(sv->ptr); + taosMemoryFree(sv->ptr); } else if (sv->type == FST_ARRAY) { taosArrayDestroy(sv->arr); } - free(sv); + taosMemoryFree(sv); } StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) { - StartWithStateValue* nsv = calloc(1, sizeof(StartWithStateValue)); + StartWithStateValue* nsv = taosMemoryCalloc(1, sizeof(StartWithStateValue)); if (nsv == NULL) { return NULL; } @@ -62,7 +62,7 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) { nsv->val = sv->val; } else if (nsv->type == FST_CHAR) { size_t len = strlen(sv->ptr); - nsv->ptr = (char*)calloc(1, len + 1); + nsv->ptr = (char*)taosMemoryCalloc(1, len + 1); memcpy(nsv->ptr, sv->ptr, len); } else if (nsv->type == FST_ARRAY) { // @@ -137,7 +137,7 @@ AutomationFunc automFuncs[] = { }; AutomationCtx* automCtxCreate(void* data, AutomationType atype) { - AutomationCtx* ctx = calloc(1, sizeof(AutomationCtx)); + AutomationCtx* ctx = taosMemoryCalloc(1, sizeof(AutomationCtx)); if (ctx == NULL) { return NULL; } @@ -158,7 +158,7 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) { if (data != NULL) { char* src = (char*)data; size_t len = strlen(src); - dst = (char*)calloc(1, len * sizeof(char) + 1); + dst = (char*)taosMemoryCalloc(1, len * sizeof(char) + 1); memcpy(dst, src, len); } @@ -169,6 +169,6 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) { } void automCtxDestroy(AutomationCtx* ctx) { startWithStateValueDestroy(ctx->stdata); - free(ctx->data); - free(ctx); + taosMemoryFree(ctx->data); + taosMemoryFree(ctx); } diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index 8cb2ff9246..6a161ba7e9 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -81,7 +81,7 @@ static int writeCtxDoFlush(WriterCtx* ctx) { } WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity) { - WriterCtx* ctx = calloc(1, sizeof(WriterCtx)); + WriterCtx* ctx = taosMemoryCalloc(1, sizeof(WriterCtx)); if (ctx == NULL) { return NULL; } ctx->type = type; @@ -112,7 +112,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int goto END; } } else if (ctx->type == TMemory) { - ctx->mem.buf = calloc(1, sizeof(char) * capacity); + ctx->mem.buf = taosMemoryCalloc(1, sizeof(char) * capacity); ctx->mem.capa = capacity; } ctx->write = writeCtxDoWrite; @@ -126,13 +126,13 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int return ctx; END: - if (ctx->type == TMemory) { free(ctx->mem.buf); } - free(ctx); + if (ctx->type == TMemory) { taosMemoryFree(ctx->mem.buf); } + taosMemoryFree(ctx); return NULL; } void writerCtxDestroy(WriterCtx* ctx, bool remove) { if (ctx->type == TMemory) { - free(ctx->mem.buf); + taosMemoryFree(ctx->mem.buf); } else { ctx->flush(ctx); taosCloseFile(&ctx->file.pFile); @@ -150,11 +150,11 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { } if (remove) { unlink(ctx->file.buf); } } - free(ctx); + taosMemoryFree(ctx); } FstCountingWriter* fstCountingWriterCreate(void* wrt) { - FstCountingWriter* cw = calloc(1, sizeof(FstCountingWriter)); + FstCountingWriter* cw = taosMemoryCalloc(1, sizeof(FstCountingWriter)); if (cw == NULL) { return NULL; } cw->wrt = wrt; @@ -165,7 +165,7 @@ void fstCountingWriterDestroy(FstCountingWriter* cw) { // free wrt object: close fd or free mem fstCountingWriterFlush(cw); // writerCtxDestroy((WriterCtx *)(cw->wrt)); - free(cw); + taosMemoryFree(cw); } int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len) { @@ -203,13 +203,13 @@ int fstCountingWriterFlush(FstCountingWriter* write) { void fstCountingWriterPackUintIn(FstCountingWriter* writer, uint64_t n, uint8_t nBytes) { assert(1 <= nBytes && nBytes <= 8); - uint8_t* buf = calloc(8, sizeof(uint8_t)); + uint8_t* buf = taosMemoryCalloc(8, sizeof(uint8_t)); for (uint8_t i = 0; i < nBytes; i++) { buf[i] = (uint8_t)n; n = n >> 8; } fstCountingWriterWrite(writer, buf, nBytes); - free(buf); + taosMemoryFree(buf); return; } diff --git a/source/libs/index/src/index_fst_node.c b/source/libs/index/src/index_fst_node.c index 5cdf6adb31..a0d59150d7 100644 --- a/source/libs/index/src/index_fst_node.c +++ b/source/libs/index/src/index_fst_node.c @@ -15,7 +15,7 @@ #include "index_fst_node.h" FstBuilderNode* fstBuilderNodeDefault() { - FstBuilderNode* bn = malloc(sizeof(FstBuilderNode)); + FstBuilderNode* bn = taosMemoryMalloc(sizeof(FstBuilderNode)); bn->isFinal = false; bn->finalOutput = 0; bn->trans = taosArrayInit(16, sizeof(FstTransition)); @@ -25,7 +25,7 @@ void fstBuilderNodeDestroy(FstBuilderNode* node) { if (node == NULL) { return; } taosArrayDestroy(node->trans); - free(node); + taosMemoryFree(node); } bool fstBuilderNodeEqual(FstBuilderNode* n1, FstBuilderNode* n2) { @@ -45,7 +45,7 @@ bool fstBuilderNodeEqual(FstBuilderNode* n1, FstBuilderNode* n2) { return true; } FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) { - FstBuilderNode* node = malloc(sizeof(FstBuilderNode)); + FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode)); if (node == NULL) { return NULL; } // diff --git a/source/libs/index/src/index_fst_registry.c b/source/libs/index/src/index_fst_registry.c index b28b518fc1..7b6b8df25f 100644 --- a/source/libs/index/src/index_fst_registry.c +++ b/source/libs/index/src/index_fst_registry.c @@ -65,13 +65,13 @@ static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) { } FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { - FstRegistry* registry = malloc(sizeof(FstRegistry)); + FstRegistry* registry = taosMemoryMalloc(sizeof(FstRegistry)); if (registry == NULL) { return NULL; } uint64_t nCells = tableSize * mruSize; SArray* tb = (SArray*)taosArrayInit(nCells, sizeof(FstRegistryCell)); if (NULL == tb) { - free(registry); + taosMemoryFree(registry); return NULL; } @@ -96,7 +96,7 @@ void fstRegistryDestroy(FstRegistry* registry) { fstBuilderNodeDestroy(cell->node); } taosArrayDestroy(tb); - free(registry); + taosMemoryFree(registry); } FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNode) { @@ -105,7 +105,7 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo uint64_t start = registry->mruSize * bucket; uint64_t end = start + registry->mruSize; - FstRegistryEntry* entry = malloc(sizeof(FstRegistryEntry)); + FstRegistryEntry* entry = taosMemoryMalloc(sizeof(FstRegistryEntry)); if (end - start == 1) { FstRegistryCell* cell = taosArrayGet(registry->table, start); // cell->isNode && @@ -166,5 +166,5 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo return entry; } void fstRegistryEntryDestroy(FstRegistryEntry* entry) { - free(entry); + taosMemoryFree(entry); } diff --git a/source/libs/index/src/index_fst_util.c b/source/libs/index/src/index_fst_util.c index f08a48c34e..f9581f7202 100644 --- a/source/libs/index/src/index_fst_util.c +++ b/source/libs/index/src/index_fst_util.c @@ -78,10 +78,10 @@ CompiledAddr unpackDelta(char* data, uint64_t len, uint64_t nodeAddr) { // FstSlice fstSliceCreate(uint8_t* data, uint64_t len) { - FstString* str = (FstString*)malloc(sizeof(FstString)); + FstString* str = (FstString*)taosMemoryMalloc(sizeof(FstString)); str->ref = 1; str->len = len; - str->data = malloc(len * sizeof(uint8_t)); + str->data = taosMemoryMalloc(len * sizeof(uint8_t)); memcpy(str->data, data, len); FstSlice s = {.str = str, .start = 0, .end = len - 1}; @@ -101,10 +101,10 @@ FstSlice fstSliceDeepCopy(FstSlice* s, int32_t start, int32_t end) { uint8_t* data = fstSliceData(s, &slen); assert(tlen <= slen); - uint8_t* buf = malloc(sizeof(uint8_t) * tlen); + uint8_t* buf = taosMemoryMalloc(sizeof(uint8_t) * tlen); memcpy(buf, data + start, tlen); - FstString* str = malloc(sizeof(FstString)); + FstString* str = taosMemoryMalloc(sizeof(FstString)); str->data = buf; str->len = tlen; str->ref = 1; @@ -128,8 +128,8 @@ void fstSliceDestroy(FstSlice* s) { FstString* str = s->str; str->ref--; if (str->ref == 0) { - free(str->data); - free(str); + taosMemoryFree(str->data); + taosMemoryFree(str); s->str = NULL; } } @@ -161,7 +161,7 @@ int fstSliceCompare(FstSlice* a, FstSlice* b) { } // FstStack* fstStackCreate(size_t elemSize, StackFreeElem freeFn) { -// FstStack *s = calloc(1, sizeof(FstStack)); +// FstStack *s = taosMemoryCalloc(1, sizeof(FstStack)); // if (s == NULL) { return NULL; } // s-> // s->freeFn diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 780b7160fc..53813e13e6 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -59,7 +59,7 @@ static void tfileGenFileName(char* filename, uint64_t suid, const char* col, static void tfileGenFileFullName(char* fullname, const char* path, uint64_t suid, const char* col, int32_t version); TFileCache* tfileCacheCreate(const char* path) { - TFileCache* tcache = calloc(1, sizeof(TFileCache)); + TFileCache* tcache = taosMemoryCalloc(1, sizeof(TFileCache)); if (tcache == NULL) { return NULL; } @@ -113,7 +113,7 @@ void tfileCacheDestroy(TFileCache* tcache) { reader = taosHashIterate(tcache->tableCache, reader); } taosHashCleanup(tcache->tableCache); - free(tcache); + taosMemoryFree(tcache); } TFileReader* tfileCacheGet(TFileCache* tcache, ICacheKey* key) { @@ -145,7 +145,7 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) { return; } TFileReader* tfileReaderCreate(WriterCtx* ctx) { - TFileReader* reader = calloc(1, sizeof(TFileReader)); + TFileReader* reader = taosMemoryCalloc(1, sizeof(TFileReader)); if (reader == NULL) { return NULL; } @@ -181,7 +181,7 @@ void tfileReaderDestroy(TFileReader* reader) { // T_REF_INC(reader); fstDestroy(reader->fst); writerCtxDestroy(reader->ctx, reader->remove); - free(reader); + taosMemoryFree(reader); } int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResult* tr) { @@ -218,7 +218,7 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul } fstSliceDestroy(&key); if (hasJson) { - free(p); + taosMemoryFree(p); } } else if (qtype == QUERY_PREFIX) { // handle later @@ -269,7 +269,7 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const c return reader; } TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) { - TFileWriter* tw = calloc(1, sizeof(TFileWriter)); + TFileWriter* tw = taosMemoryCalloc(1, sizeof(TFileWriter)); if (tw == NULL) { indexError("index: %" PRIu64 " failed to alloc TFilerWriter", header->suid); return NULL; @@ -296,7 +296,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { } int32_t bufLimit = 64 * 4096, offset = 0; - // char* buf = calloc(1, sizeof(char) * bufLimit); + // char* buf = taosMemoryCalloc(1, sizeof(char) * bufLimit); // char* p = buf; int32_t sz = taosArrayGetSize((SArray*)data); int32_t fstOffset = tw->offset; @@ -318,13 +318,13 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // check buf has enough space or not int32_t ttsz = TF_TABLE_TATOAL_SIZE(tbsz); - char* buf = calloc(1, ttsz * sizeof(char)); + char* buf = taosMemoryCalloc(1, ttsz * sizeof(char)); char* p = buf; tfileSerialTableIdsToBuf(p, v->tableId); tw->ctx->write(tw->ctx, buf, ttsz); v->offset = tw->offset; tw->offset += ttsz; - free(buf); + taosMemoryFree(buf); } tw->fb = fstBuilderCreate(tw->ctx, 0); @@ -359,14 +359,14 @@ void tfileWriterClose(TFileWriter* tw) { return; } writerCtxDestroy(tw->ctx, false); - free(tw); + taosMemoryFree(tw); } void tfileWriterDestroy(TFileWriter* tw) { if (tw == NULL) { return; } writerCtxDestroy(tw->ctx, false); - free(tw); + taosMemoryFree(tw); } IndexTFile* indexTFileCreate(const char* path) { @@ -375,7 +375,7 @@ IndexTFile* indexTFileCreate(const char* path) { return NULL; } - IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); + IndexTFile* tfile = taosMemoryCalloc(1, sizeof(IndexTFile)); if (tfile == NULL) { tfileCacheDestroy(cache); return NULL; @@ -389,7 +389,7 @@ void indexTFileDestroy(IndexTFile* tfile) { return; } tfileCacheDestroy(tfile->cache); - free(tfile); + taosMemoryFree(tfile); } int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTempResult* result) { @@ -433,7 +433,7 @@ static bool tfileIteratorNext(Iterate* iiter) { int32_t sz = 0; char* ch = (char*)fstSliceData(&rt->data, &sz); - colVal = calloc(1, sz + 1); + colVal = taosMemoryCalloc(1, sz + 1); memcpy(colVal, ch, sz); offset = (uint64_t)(rt->out.out); @@ -453,7 +453,7 @@ static bool tfileIteratorNext(Iterate* iiter) { static IterateValue* tifileIterateGetValue(Iterate* iter) { return &iter->val; } static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) { - TFileFstIter* tIter = calloc(1, sizeof(TFileFstIter)); + TFileFstIter* tIter = taosMemoryCalloc(1, sizeof(TFileFstIter)); if (tIter == NULL) { return NULL; } @@ -470,10 +470,10 @@ Iterate* tfileIteratorCreate(TFileReader* reader) { return NULL; } - Iterate* iter = calloc(1, sizeof(Iterate)); + Iterate* iter = taosMemoryCalloc(1, sizeof(Iterate)); iter->iter = tfileFstIteratorCreate(reader); if (iter->iter == NULL) { - free(iter); + taosMemoryFree(iter); return NULL; } iter->next = tfileIteratorNext; @@ -494,9 +494,9 @@ void tfileIteratorDestroy(Iterate* iter) { streamWithStateDestroy(tIter->st); fstStreamBuilderDestroy(tIter->fb); automCtxDestroy(tIter->ctx); - free(tIter); + taosMemoryFree(tIter); - free(iter); + taosMemoryFree(iter); } TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) { @@ -530,7 +530,7 @@ static int tfileValueCompare(const void* a, const void* b, const void* param) { } TFileValue* tfileValueCreate(char* val) { - TFileValue* tf = calloc(1, sizeof(TFileValue)); + TFileValue* tf = taosMemoryCalloc(1, sizeof(TFileValue)); if (tf == NULL) { return NULL; } @@ -547,8 +547,8 @@ int tfileValuePush(TFileValue* tf, uint64_t val) { } void tfileValueDestroy(TFileValue* tf) { taosArrayDestroy(tf->tableId); - free(tf->colVal); - free(tf); + taosMemoryFree(tf->colVal); + taosMemoryFree(tf); } static void tfileSerialTableIdsToBuf(char* buf, SArray* ids) { int sz = taosArrayGetSize(ids); @@ -636,7 +636,7 @@ static int tfileReaderLoadFst(TFileReader* reader) { // current load fst into memory, refactor it later int fstSize = size - reader->header.fstOffset - sizeof(tfileMagicNumber); - char* buf = calloc(1, fstSize); + char* buf = taosMemoryCalloc(1, fstSize); if (buf == NULL) { return -1; } @@ -651,7 +651,7 @@ static int tfileReaderLoadFst(TFileReader* reader) { FstSlice st = fstSliceCreate((uint8_t*)buf, nread); reader->fst = fstCreate(&st); - free(buf); + taosMemoryFree(buf); fstSliceDestroy(&st); return reader->fst != NULL ? 0 : -1; @@ -744,7 +744,7 @@ static SArray* tfileGetFileList(const char* path) { } size_t len = strlen(path) + 1 + strlen(file) + 1; - char* buf = calloc(1, len); + char* buf = taosMemoryCalloc(1, len); sprintf(buf, "%s/%s", path, file); taosArrayPush(files, &buf); } @@ -761,7 +761,7 @@ static int tfileRmExpireFile(SArray* result) { } static void tfileDestroyFileName(void* elem) { char* p = *(char**)elem; - free(p); + taosMemoryFree(p); } static int tfileCompare(const void* a, const void* b) { const char* as = *(char**)a; diff --git a/source/libs/index/src/index_util.c b/source/libs/index/src/index_util.c index dfe4e273a9..65c16ca65b 100644 --- a/source/libs/index/src/index_util.c +++ b/source/libs/index/src/index_util.c @@ -41,7 +41,7 @@ void iIntersection(SArray *inters, SArray *final) { if (sz <= 0) { return; } - MergeIndex *mi = calloc(sz, sizeof(MergeIndex)); + MergeIndex *mi = taosMemoryCalloc(sz, sizeof(MergeIndex)); for (int i = 0; i < sz; i++) { SArray *t = taosArrayGetP(inters, i); mi[i].len = taosArrayGetSize(t); @@ -67,7 +67,7 @@ void iIntersection(SArray *inters, SArray *final) { taosArrayPush(final, &tgt); } } - tfree(mi); + taosMemoryFreeClear(mi); } void iUnion(SArray *inters, SArray *final) { int32_t sz = taosArrayGetSize(inters); @@ -79,7 +79,7 @@ void iUnion(SArray *inters, SArray *final) { return; } - MergeIndex *mi = calloc(sz, sizeof(MergeIndex)); + MergeIndex *mi = taosMemoryCalloc(sz, sizeof(MergeIndex)); for (int i = 0; i < sz; i++) { SArray *t = taosArrayGetP(inters, i); mi[i].len = taosArrayGetSize(t); @@ -113,7 +113,7 @@ void iUnion(SArray *inters, SArray *final) { break; } } - tfree(mi); + taosMemoryFreeClear(mi); } void iExcept(SArray *total, SArray *except) { @@ -156,7 +156,7 @@ int verdataCompare(const void *a, const void *b) { } SIdxTempResult *sIdxTempResultCreate() { - SIdxTempResult *tr = calloc(1, sizeof(SIdxTempResult)); + SIdxTempResult *tr = taosMemoryCalloc(1, sizeof(SIdxTempResult)); tr->total = taosArrayInit(4, sizeof(uint64_t)); tr->added = taosArrayInit(4, sizeof(uint64_t)); diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc index 410d5b7021..94923726dd 100644 --- a/source/libs/index/test/fstTest.cc +++ b/source/libs/index/test/fstTest.cc @@ -55,7 +55,7 @@ class FstReadMemory { memset((void*)&_s, 0, sizeof(_s)); } bool init() { - char* buf = (char*)calloc(1, sizeof(char) * _size); + char* buf = (char*)taosMemoryCalloc(1, sizeof(char) * _size); int nRead = fstCountingWriterRead(_w, (uint8_t*)buf, _size); if (nRead <= 0) { return false; @@ -63,7 +63,7 @@ class FstReadMemory { _size = nRead; _s = fstSliceCreate((uint8_t*)buf, _size); _fst = fstCreate(&_s); - free(buf); + taosMemoryFree(buf); return _fst != NULL; } bool Get(const std::string& key, uint64_t* val) { @@ -230,7 +230,7 @@ void checkFstLongTerm() { // for (int i = 0; i < result.size(); i++) { // assert(result[i] == i); // check result //} - // free(ctx); + // taosMemoryFree(ctx); // delete m; } void checkFstCheckIterator() { @@ -266,7 +266,7 @@ void checkFstCheckIterator() { // assert(result[i] == i); // check result } - free(ctx); + taosMemoryFree(ctx); delete m; } diff --git a/source/libs/index/test/fstUT.cc b/source/libs/index/test/fstUT.cc index 6e9c88bc79..1bdc7fc9c9 100644 --- a/source/libs/index/test/fstUT.cc +++ b/source/libs/index/test/fstUT.cc @@ -75,7 +75,7 @@ class FstReadMemory { memset((void*)&_s, 0, sizeof(_s)); } bool init() { - char* buf = (char*)calloc(1, sizeof(char) * _size); + char* buf = (char*)taosMemoryCalloc(1, sizeof(char) * _size); int nRead = fstCountingWriterRead(_w, (uint8_t*)buf, _size); if (nRead <= 0) { return false; @@ -83,7 +83,7 @@ class FstReadMemory { _size = nRead; _s = fstSliceCreate((uint8_t*)buf, _size); _fst = fstCreate(&_s); - free(buf); + taosMemoryFreeClear(buf); return _fst != NULL; } bool Get(const std::string& key, uint64_t* val) { diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 5f339f2865..0e4eb060cf 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -81,7 +81,7 @@ class FstReadMemory { memset((void*)&_s, 0, sizeof(_s)); } bool init() { - char* buf = (char*)calloc(1, sizeof(char) * _size); + char* buf = (char*)taosMemoryCalloc(1, sizeof(char) * _size); int nRead = fstCountingWriterRead(_w, (uint8_t*)buf, _size); if (nRead <= 0) { return false; @@ -89,7 +89,7 @@ class FstReadMemory { _size = nRead; _s = fstSliceCreate((uint8_t*)buf, _size); _fst = fstCreate(&_s); - free(buf); + taosMemoryFree(buf); return _fst != NULL; } bool Get(const std::string& key, uint64_t* val) { @@ -227,7 +227,7 @@ void checkFstPrefixSearch() { assert(result[i] == i); // check result } - free(ctx); + taosMemoryFree(ctx); delete m; } void validateFst() { @@ -446,9 +446,9 @@ class IndexTFileEnv : public ::testing::Test { }; static TFileValue* genTFileValue(const char* val) { - TFileValue* tv = (TFileValue*)calloc(1, sizeof(TFileValue)); + TFileValue* tv = (TFileValue*)taosMemoryCalloc(1, sizeof(TFileValue)); int32_t vlen = strlen(val) + 1; - tv->colVal = (char*)calloc(1, vlen); + tv->colVal = (char*)taosMemoryCalloc(1, vlen); memcpy(tv->colVal, val, vlen); tv->tableId = (SArray*)taosArrayInit(1, sizeof(uint64_t)); @@ -460,9 +460,9 @@ static TFileValue* genTFileValue(const char* val) { } static void destroyTFileValue(void* val) { TFileValue* tv = (TFileValue*)val; - free(tv->colVal); + taosMemoryFree(tv->colVal); taosArrayDestroy(tv->tableId); - free(tv); + taosMemoryFree(tv); } TEST_F(IndexTFileEnv, test_tfile_write) { TFileValue* v1 = genTFileValue("ab"); diff --git a/source/libs/monitor/src/monitor.c b/source/libs/monitor/src/monitor.c index aa5eafd8b2..b92c08d51c 100644 --- a/source/libs/monitor/src/monitor.c +++ b/source/libs/monitor/src/monitor.c @@ -60,7 +60,7 @@ void monCleanup() { } SMonInfo *monCreateMonitorInfo() { - SMonInfo *pMonitor = calloc(1, sizeof(SMonInfo)); + SMonInfo *pMonitor = taosMemoryCalloc(1, sizeof(SMonInfo)); if (pMonitor == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -88,7 +88,7 @@ void monCleanupMonitorInfo(SMonInfo *pMonitor) { tsMonitor.state.time = pMonitor->curTime; taosArrayDestroy(pMonitor->logs); tjsonDelete(pMonitor->pJson); - free(pMonitor); + taosMemoryFree(pMonitor); } void monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo) { @@ -381,6 +381,6 @@ void monSendReport(SMonInfo *pMonitor) { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.comp ? HTTP_GZIP : HTTP_FLAT; taosSendHttpReport(tsMonitor.server, tsMonitor.port, pCont, strlen(pCont), flag); - free(pCont); + taosMemoryFree(pCont); } } diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 60692323f5..078f3ab3e6 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -141,7 +141,7 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: - pDst->datum.p = malloc(pSrc->node.resType.bytes + VARSTR_HEADER_SIZE + 1); + pDst->datum.p = taosMemoryMalloc(pSrc->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pDst->datum.p) { nodesDestroyNode(pDst); return NULL; @@ -210,7 +210,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) { static STableMeta* tableMetaClone(const STableMeta* pSrc) { int32_t len = TABLE_META_SIZE(pSrc); - STableMeta* pDst = malloc(len); + STableMeta* pDst = taosMemoryMalloc(len); if (NULL == pDst) { return NULL; } @@ -220,7 +220,7 @@ static STableMeta* tableMetaClone(const STableMeta* pSrc) { static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) { int32_t len = VGROUPS_INFO_SIZE(pSrc); - SVgroupsInfo* pDst = malloc(len); + SVgroupsInfo* pDst = taosMemoryMalloc(len); if (NULL == pDst) { return NULL; } diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 37be210610..1acc3c51c5 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -1480,7 +1480,7 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) { case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: { - pNode->datum.p = calloc(1, pNode->node.resType.bytes + VARSTR_HEADER_SIZE + 1); + pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pNode->datum.p) { code = TSDB_CODE_OUT_OF_MEMORY; break; diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index d529ee2b1a..5345e84cdb 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -22,7 +22,7 @@ #include "thash.h" static SNode* makeNode(ENodeType type, size_t size) { - SNode* p = calloc(1, size); + SNode* p = taosMemoryCalloc(1, size); if (NULL == p) { return NULL; } @@ -207,9 +207,9 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { case QUERY_NODE_VALUE: { SValueNode* pValue = (SValueNode*)*pNode; - tfree(pValue->literal); + taosMemoryFreeClear(pValue->literal); if (IS_VAR_DATA_TYPE(pValue->node.resType.type)) { - tfree(pValue->datum.p); + taosMemoryFreeClear(pValue->datum.p); } break; @@ -222,8 +222,8 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { break; case QUERY_NODE_REAL_TABLE: { SRealTableNode* pReal = (SRealTableNode*)*pNode; - tfree(pReal->pMeta); - tfree(pReal->pVgroupList); + taosMemoryFreeClear(pReal->pMeta); + taosMemoryFreeClear(pReal->pVgroupList); break; } case QUERY_NODE_TEMP_TABLE: @@ -262,8 +262,8 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { size_t size = taosArrayGetSize(pStmt->pDataBlocks); for (size_t i = 0; i < size; ++i) { SVgDataBlocks* pVg = taosArrayGetP(pStmt->pDataBlocks, i); - tfree(pVg->pData); - tfree(pVg); + taosMemoryFreeClear(pVg->pData); + taosMemoryFreeClear(pVg); } taosArrayDestroy(pStmt->pDataBlocks); break; @@ -292,7 +292,7 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { default: break; } - tfree(*pNode); + taosMemoryFreeClear(*pNode); return DEAL_RES_CONTINUE; } @@ -304,7 +304,7 @@ void nodesDestroyNode(SNodeptr pNode) { } SNodeList* nodesMakeList() { - SNodeList* p = calloc(1, sizeof(SNodeList)); + SNodeList* p = taosMemoryCalloc(1, sizeof(SNodeList)); if (NULL == p) { return NULL; } @@ -315,7 +315,7 @@ int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode) { if (NULL == pList || NULL == pNode) { return TSDB_CODE_SUCCESS; } - SListCell* p = calloc(1, sizeof(SListCell)); + SListCell* p = taosMemoryCalloc(1, sizeof(SListCell)); if (NULL == p) { terrno = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY; @@ -370,7 +370,7 @@ int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) { } pTarget->pTail = pSrc->pTail; pTarget->length += pSrc->length; - tfree(pSrc); + taosMemoryFreeClear(pSrc); return TSDB_CODE_SUCCESS; } @@ -395,7 +395,7 @@ SListCell* nodesListErase(SNodeList* pList, SListCell* pCell) { } SListCell* pNext = pCell->pNext; nodesDestroyNode(pCell->pNode); - tfree(pCell); + taosMemoryFreeClear(pCell); --(pList->length); return pNext; } @@ -419,7 +419,7 @@ void nodesDestroyList(SNodeList* pList) { while (NULL != pNext) { pNext = nodesListErase(pList, pNext); } - tfree(pList); + taosMemoryFreeClear(pList); } void nodesClearList(SNodeList* pList) { @@ -431,9 +431,9 @@ void nodesClearList(SNodeList* pList) { while (NULL != pNext) { SListCell* tmp = pNext; pNext = pNext->pNext; - tfree(tmp); + taosMemoryFreeClear(tmp); } - tfree(pList); + taosMemoryFreeClear(pList); } void* nodesGetValueFromNode(SValueNode *pNode) { diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4f27743b2b..9630b0d68c 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -481,7 +481,7 @@ SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { CHECK_RAW_EXPR_NODE(pNode); SNode* tmp = ((SRawExprNode*)pNode)->pNode; - tfree(pNode); + taosMemoryFreeClear(pNode); return tmp; } diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index e992f150aa..5c38ccaff8 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -29,7 +29,7 @@ extern void ParseTrace(FILE*, char*); int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) { SAstCreateContext cxt; initAstCreateContext(pParseCxt, &cxt); - void *pParser = ParseAlloc(malloc); + void *pParser = ParseAlloc((FMalloc)taosMemoryMalloc); int32_t i = 0; while (1) { SToken t0 = {0}; @@ -73,9 +73,9 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) { } abort_parse: - ParseFree(pParser, free); + ParseFree(pParser, (FFree)taosMemoryFree); if (cxt.valid) { - *pQuery = calloc(1, sizeof(SQuery)); + *pQuery = taosMemoryCalloc(1, sizeof(SQuery)); if (NULL == *pQuery) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 6e01b7b12e..b2fc39d064 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -277,7 +277,7 @@ static int32_t buildOutput(SInsertParseContext* pCxt) { } for (size_t i = 0; i < numOfVg; ++i) { STableDataBlocks* src = taosArrayGetP(pCxt->pVgDataBlocks, i); - SVgDataBlocks* dst = calloc(1, sizeof(SVgDataBlocks)); + SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == dst) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -684,7 +684,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* pColList->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED; if (!isOrdered) { - pColList->colIdxInfo = calloc(pColList->numOfBound, sizeof(SBoundIdxInfo)); + pColList->colIdxInfo = taosMemoryCalloc(pColList->numOfBound, sizeof(SBoundIdxInfo)); if (NULL == pColList->colIdxInfo) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -760,7 +760,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pTagsSchema, // todo construct payload - tfree(row); + taosMemoryFreeClear(row); return 0; } @@ -903,7 +903,7 @@ static int32_t parseValuesClause(SInsertParseContext* pCxt, STableDataBlocks* da } static void destroyInsertParseContextForTable(SInsertParseContext* pCxt) { - tfree(pCxt->pTableMeta); + taosMemoryFreeClear(pCxt->pTableMeta); destroyBoundColumnInfo(&pCxt->tags); tdDestroyKVRowBuilder(&pCxt->tagsBuilder); } @@ -913,16 +913,16 @@ static void destroyDataBlock(STableDataBlocks* pDataBlock) { return; } - tfree(pDataBlock->pData); + taosMemoryFreeClear(pDataBlock->pData); if (!pDataBlock->cloned) { // free the refcount for metermeta if (pDataBlock->pTableMeta != NULL) { - tfree(pDataBlock->pTableMeta); + taosMemoryFreeClear(pDataBlock->pTableMeta); } destroyBoundColumnInfo(&pDataBlock->boundColumnInfo); } - tfree(pDataBlock); + taosMemoryFreeClear(pDataBlock); } static void destroyInsertParseContext(SInsertParseContext* pCxt) { @@ -1029,7 +1029,7 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - *pQuery = calloc(1, sizeof(SQuery)); + *pQuery = taosMemoryCalloc(1, sizeof(SQuery)); if (NULL == *pQuery) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index 0189ddb5ad..e516053b1e 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -47,8 +47,8 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, int32_t pColList->numOfCols = numOfCols; pColList->numOfBound = numOfCols; pColList->orderStatus = ORDER_STATUS_ORDERED; // default is ORDERED for non-bound mode - pColList->boundedColumns = calloc(pColList->numOfCols, sizeof(int32_t)); - pColList->cols = calloc(pColList->numOfCols, sizeof(SBoundColumn)); + pColList->boundedColumns = taosMemoryCalloc(pColList->numOfCols, sizeof(int32_t)); + pColList->cols = taosMemoryCalloc(pColList->numOfCols, sizeof(SBoundColumn)); pColList->colIdxInfo = NULL; pColList->flen = 0; pColList->allNullLen = 0; @@ -103,14 +103,14 @@ int32_t boundIdxCompar(const void *lhs, const void *rhs) { } void destroyBoundColumnInfo(SParsedDataColInfo* pColList) { - tfree(pColList->boundedColumns); - tfree(pColList->cols); - tfree(pColList->colIdxInfo); + taosMemoryFreeClear(pColList->boundedColumns); + taosMemoryFreeClear(pColList->cols); + taosMemoryFreeClear(pColList->colIdxInfo); } static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, const STableMeta* pTableMeta, STableDataBlocks** dataBlocks) { - STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks)); + STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks)); if (dataBuf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -123,9 +123,9 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star dataBuf->nAllocSize = dataBuf->headerSize * 2; } - dataBuf->pData = malloc(dataBuf->nAllocSize); + dataBuf->pData = taosMemoryMalloc(dataBuf->nAllocSize); if (dataBuf->pData == NULL) { - tfree(dataBuf); + taosMemoryFreeClear(dataBuf); return TSDB_CODE_TSC_OUT_OF_MEMORY; } memset(dataBuf->pData, 0, sizeof(SSubmitBlk)); @@ -190,16 +190,16 @@ static void destroyDataBlock(STableDataBlocks* pDataBlock) { return; } - tfree(pDataBlock->pData); + taosMemoryFreeClear(pDataBlock->pData); if (!pDataBlock->cloned) { // free the refcount for metermeta if (pDataBlock->pTableMeta != NULL) { - tfree(pDataBlock->pTableMeta); + taosMemoryFreeClear(pDataBlock->pTableMeta); } destroyBoundColumnInfo(&pDataBlock->boundColumnInfo); } - tfree(pDataBlock); + taosMemoryFreeClear(pDataBlock); } void destroyBlockArrayList(SArray* pDataBlockList) { @@ -283,7 +283,7 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey // allocate memory size_t nAlloc = nRows * sizeof(SBlockKeyTuple); if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) { - char *tmp = realloc(pBlkKeyInfo->pKeyTuple, nAlloc); + char *tmp = taosMemoryRealloc(pBlkKeyInfo->pKeyTuple, nAlloc); if (tmp == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -433,7 +433,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t if (ret != TSDB_CODE_SUCCESS) { taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); - tfree(blkKeyInfo.pKeyTuple); + taosMemoryFreeClear(blkKeyInfo.pKeyTuple); return ret; } @@ -444,14 +444,14 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t if (dataBuf->nAllocSize < destSize) { dataBuf->nAllocSize = (uint32_t)(destSize * 1.5); - char* tmp = realloc(dataBuf->pData, dataBuf->nAllocSize); + char* tmp = taosMemoryRealloc(dataBuf->pData, dataBuf->nAllocSize); if (tmp != NULL) { dataBuf->pData = tmp; } else { // failed to allocate memory, free already allocated memory and return error code taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); - tfree(dataBuf->pData); - tfree(blkKeyInfo.pKeyTuple); + taosMemoryFreeClear(dataBuf->pData); + taosMemoryFreeClear(blkKeyInfo.pKeyTuple); return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -462,8 +462,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t if ((code = sortRemoveDataBlockDupRows(pOneTableBlock, &blkKeyInfo)) != 0) { taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); - tfree(dataBuf->pData); - tfree(blkKeyInfo.pKeyTuple); + taosMemoryFreeClear(dataBuf->pData); + taosMemoryFreeClear(blkKeyInfo.pKeyTuple); return code; } ASSERT(blkKeyInfo.pKeyTuple != NULL && pBlocks->numOfRows > 0); @@ -492,7 +492,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t // free the table data blocks; taosHashCleanup(pVnodeDataBlockHashList); - tfree(blkKeyInfo.pKeyTuple); + taosMemoryFreeClear(blkKeyInfo.pKeyTuple); *pVgDataBlocks = pVnodeDataBlockList; return TSDB_CODE_SUCCESS; } @@ -509,7 +509,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t remain = pDataBlock->nAllocSize - pDataBlock->size; } - char *tmp = realloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); + char *tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); if (tmp != NULL) { pDataBlock->pData = tmp; memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size); diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 1dc1945f23..79651cd325 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -594,7 +594,7 @@ SToken tscReplaceStrToken(char **str, SToken *token, const char* newToken) { int32_t bsize = (int32_t)((uint64_t)token->z - (uint64_t)src); SToken ntoken; - *str = calloc(1, size); + *str = taosMemoryCalloc(1, size); strncpy(*str, src, bsize); strcat(*str, newToken); @@ -603,7 +603,7 @@ SToken tscReplaceStrToken(char **str, SToken *token, const char* newToken) { ntoken.n = (uint32_t)nsize; ntoken.z = *str + bsize; - tfree(src); + taosMemoryFreeClear(src); return ntoken; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 8c842db161..2d1882245d 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -383,7 +383,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: { - pVal->datum.p = calloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); + pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_OUT_OF_MEMORY); } @@ -585,7 +585,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) { size_t vgroupNum = taosArrayGetSize(pVgs); - *pVgsInfo = calloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupNum); + *pVgsInfo = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupNum); if (NULL == *pVgsInfo) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -640,7 +640,7 @@ static int32_t setTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTa } else if (TSDB_SYSTEM_TABLE == pRealTable->pMeta->tableType) { code = setSysTableVgroupList(pCxt, pName, pRealTable); } else { - pRealTable->pVgroupList = calloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); + pRealTable->pVgroupList = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); if (NULL == pRealTable->pVgroupList) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -932,14 +932,14 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS SCreateDbReq createReq = {0}; buildCreateDbReq(pCxt, pStmt, &createReq); - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB; pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -955,14 +955,14 @@ static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* tNameGetFullDbName(&name, dropReq.db); dropReq.ignoreNotExists = pStmt->ignoreNotExists; - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DB; pCxt->pCmdMsg->msgLen = tSerializeSDropDbReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -990,14 +990,14 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm SAlterDbReq alterReq = {0}; buildAlterDbReq(pCxt, pStmt, &alterReq); - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_DB; pCxt->pCmdMsg->msgLen = tSerializeSAlterDbReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1041,7 +1041,7 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt strcpy(tableName.tname, pStmt->tableName); tNameExtractFullName(&tableName, createReq.name); - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { tFreeSMCreateStbReq(&createReq); return TSDB_CODE_OUT_OF_MEMORY; @@ -1049,7 +1049,7 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_STB; pCxt->pCmdMsg->msgLen = tSerializeSMCreateStbReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { tFreeSMCreateStbReq(&createReq); return TSDB_CODE_OUT_OF_MEMORY; @@ -1065,14 +1065,14 @@ static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* p tNameExtractFullName(pTableName, dropReq.name); dropReq.igNotExists = ignoreNotExists; - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_DROP_STB; pCxt->pCmdMsg->msgLen = tSerializeSMDropStbReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1095,7 +1095,7 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt // todo : drop normal table or child table code = TSDB_CODE_FAILED; } - tfree(pTableMeta); + taosMemoryFreeClear(pTableMeta); } return code; @@ -1159,14 +1159,14 @@ static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pSt } } - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_STB; pCxt->pCmdMsg->msgLen = tSerializeSMAlterStbReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1185,14 +1185,14 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p return code; } - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_USE_DB; pCxt->pCmdMsg->msgLen = tSerializeSUseDbReq(NULL, 0, &usedbReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1208,14 +1208,14 @@ static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pSt createReq.superUser = 0; strcpy(createReq.pass, pStmt->password); - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_USER; pCxt->pCmdMsg->msgLen = tSerializeSCreateUserReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1234,14 +1234,14 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt strcpy(alterReq.dbname, pCxt->pParseCxt->db); } - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_USER; pCxt->pCmdMsg->msgLen = tSerializeSAlterUserReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1254,14 +1254,14 @@ static int32_t translateDropUser(STranslateContext* pCxt, SDropUserStmt* pStmt) SDropUserReq dropReq = {0}; strcpy(dropReq.user, pStmt->useName); - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_DROP_USER; pCxt->pCmdMsg->msgLen = tSerializeSDropUserReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1275,14 +1275,14 @@ static int32_t translateCreateDnode(STranslateContext* pCxt, SCreateDnodeStmt* p strcpy(createReq.fqdn, pStmt->fqdn); createReq.port = pStmt->port; - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DNODE; pCxt->pCmdMsg->msgLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1297,14 +1297,14 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt strcpy(dropReq.fqdn, pStmt->fqdn); dropReq.port = pStmt->port; - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DNODE; pCxt->pCmdMsg->msgLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1319,14 +1319,14 @@ static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pSt strcpy(cfgReq.config, pStmt->config); strcpy(cfgReq.value, pStmt->value); - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_CONFIG_DNODE; pCxt->pCmdMsg->msgLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1366,14 +1366,14 @@ static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) { // tNameGetFullDbName(&name, showReq.db); // } - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_SHOW; pCxt->pCmdMsg->msgLen = tSerializeSShowReq(NULL, 0, &showReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1383,7 +1383,7 @@ static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) { } static int32_t translateShowTables(STranslateContext* pCxt) { - SVShowTablesReq* pShowReq = calloc(1, sizeof(SVShowTablesReq)); + SVShowTablesReq* pShowReq = taosMemoryCalloc(1, sizeof(SVShowTablesReq)); SArray* array = NULL; int32_t code = getDBVgInfo(pCxt, pCxt->pParseCxt->db, &array); @@ -1393,7 +1393,7 @@ static int32_t translateShowTables(STranslateContext* pCxt) { SVgroupInfo* info = taosArrayGet(array, 0); pShowReq->head.vgId = htonl(info->vgId); - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1514,14 +1514,14 @@ static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt return code; } - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_SMA; pCxt->pCmdMsg->msgLen = tSerializeSMCreateSmaReq(NULL, 0, &createSmaReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1544,14 +1544,14 @@ static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt SVDropTSmaReq dropSmaReq = {0}; strcpy(dropSmaReq.indexName, pStmt->indexName); - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_VND_DROP_SMA; pCxt->pCmdMsg->msgLen = tSerializeSVDropTSmaReq(NULL, &dropSmaReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1564,14 +1564,14 @@ static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* pStmt) { SMCreateQnodeReq createReq = { .dnodeId = pStmt->dnodeId }; - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_DND_CREATE_QNODE; pCxt->pCmdMsg->msgLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1583,14 +1583,14 @@ static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* p static int32_t translateDropQnode(STranslateContext* pCxt, SDropQnodeStmt* pStmt) { SDDropQnodeReq dropReq = { .dnodeId = pStmt->dnodeId }; - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_DND_DROP_QNODE; pCxt->pCmdMsg->msgLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1626,14 +1626,14 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p tNameExtractFullName(&name, createReq.name); createReq.igExists = pStmt->ignoreExists; - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_TOPIC; pCxt->pCmdMsg->msgLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1652,14 +1652,14 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt tNameExtractFullName(&name, dropReq.name); dropReq.igNotExists = pStmt->ignoreNotExists; - pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = TDMT_MND_DROP_TOPIC; pCxt->pCmdMsg->msgLen = tSerializeSMDropTopicReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1775,7 +1775,7 @@ int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** p if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) { SSelectStmt* pSelect = (SSelectStmt*) pRoot; *numOfCols = LIST_LENGTH(pSelect->pProjectionList); - *pSchema = calloc((*numOfCols), sizeof(SSchema)); + *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1805,8 +1805,8 @@ static void destroyTranslateContext(STranslateContext* pCxt) { } if (NULL != pCxt->pCmdMsg) { - tfree(pCxt->pCmdMsg->pMsg); - tfree(pCxt->pCmdMsg); + taosMemoryFreeClear(pCxt->pCmdMsg->pMsg); + taosMemoryFreeClear(pCxt->pCmdMsg); } taosHashCleanup(pCxt->pDbs); @@ -1967,9 +1967,9 @@ static void toSchema(const SColumnDefNode* pCol, int32_t colId, SSchema* pSchema } static void destroyCreateTbReq(SVCreateTbReq* pReq) { - tfree(pReq->dbFName); - tfree(pReq->name); - tfree(pReq->ntbCfg.pSchema); + taosMemoryFreeClear(pReq->dbFName); + taosMemoryFreeClear(pReq->name); + taosMemoryFreeClear(pReq->ntbCfg.pSchema); } static int32_t buildNormalTableBatchReq(int32_t acctId, const char* pDbName, const char* pTableName, @@ -1984,7 +1984,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const char* pDbName, con req.dbFName = strdup(dbFName); req.name = strdup(pTableName); req.ntbCfg.nCols = LIST_LENGTH(pColumns); - req.ntbCfg.pSchema = calloc(req.ntbCfg.nCols, sizeof(SSchema)); + req.ntbCfg.pSchema = taosMemoryCalloc(req.ntbCfg.nCols, sizeof(SSchema)); if (NULL == req.name || NULL == req.ntbCfg.pSchema) { destroyCreateTbReq(&req); return TSDB_CODE_OUT_OF_MEMORY; @@ -2010,7 +2010,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const char* pDbName, con static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* pBufArray) { int tlen = sizeof(SMsgHead) + tSerializeSVCreateTbBatchReq(NULL, &(pTbBatch->req)); - void* buf = malloc(tlen); + void* buf = taosMemoryMalloc(tlen); if (NULL == buf) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -2019,7 +2019,7 @@ static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); tSerializeSVCreateTbBatchReq(&pBuf, &(pTbBatch->req)); - SVgDataBlocks* pVgData = calloc(1, sizeof(SVgDataBlocks)); + SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -2036,13 +2036,13 @@ static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) { size_t size = taosArrayGetSize(pTbBatch->req.pArray); for(int32_t i = 0; i < size; ++i) { SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i); - tfree(pTableReq->dbFName); - tfree(pTableReq->name); + taosMemoryFreeClear(pTableReq->dbFName); + taosMemoryFreeClear(pTableReq->name); if (pTableReq->type == TSDB_NORMAL_TABLE) { - tfree(pTableReq->ntbCfg.pSchema); + taosMemoryFreeClear(pTableReq->ntbCfg.pSchema); } else if (pTableReq->type == TSDB_CHILD_TABLE) { - tfree(pTableReq->ctbCfg.pTag); + taosMemoryFreeClear(pTableReq->ctbCfg.pTag); } } @@ -2065,8 +2065,8 @@ static void destroyCreateTbReqArray(SArray* pArray) { size_t size = taosArrayGetSize(pArray); for (size_t i = 0; i < size; ++i) { SVgDataBlocks* pVg = taosArrayGetP(pArray, i); - tfree(pVg->pData); - tfree(pVg); + taosMemoryFreeClear(pVg->pData); + taosMemoryFreeClear(pVg); } taosArrayDestroy(pArray); } @@ -2274,7 +2274,7 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla addCreateTbReqIntoVgroup(pCxt->pParseCxt->acctId, pVgroupHashmap, pStmt->dbName, pStmt->tableName, row, pSuperTableMeta->uid, &info); } - tfree(pSuperTableMeta); + taosMemoryFreeClear(pSuperTableMeta); tdDestroyKVRowBuilder(&kvRowBuilder); return code; } diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 2e3936a6fb..80d04c5ee4 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -122,7 +122,7 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) { assert(pTableMeta != NULL); size_t size = getTableMetaSize(pTableMeta); - STableMeta* p = malloc(size); + STableMeta* p = taosMemoryMalloc(size); memcpy(p, pTableMeta, size); return p; } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 08f316b539..92bd6f111b 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -53,10 +53,10 @@ void qDestroyQuery(SQuery* pQueryNode) { return; } nodesDestroyNode(pQueryNode->pRoot); - tfree(pQueryNode->pResSchema); + taosMemoryFreeClear(pQueryNode->pResSchema); if (NULL != pQueryNode->pCmdMsg) { - tfree(pQueryNode->pCmdMsg->pMsg); - tfree(pQueryNode->pCmdMsg); + taosMemoryFreeClear(pQueryNode->pCmdMsg->pMsg); + taosMemoryFreeClear(pQueryNode->pCmdMsg); } - tfree(pQueryNode); + taosMemoryFreeClear(pQueryNode); } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 8f9443d4ec..451587c8bf 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -73,7 +73,7 @@ ** which is ParseTOKENTYPE. The entry in the union ** for terminal symbols is called "yy0". ** YYSTACKDEPTH is the maximum depth of the parser's stack. If -** zero the stack is dynamically sized using realloc() +** zero the stack is dynamically sized using taosMemoryRealloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument ** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter @@ -1325,10 +1325,10 @@ static int yyGrowStack(yyParser *p){ newSize = p->yystksz*2 + 100; idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; if( p->yystack==&p->yystk0 ){ - pNew = malloc(newSize*sizeof(pNew[0])); + pNew = taosMemoryMalloc(newSize*sizeof(pNew[0])); if( pNew ) pNew[0] = p->yystk0; }else{ - pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + pNew = taosMemoryRealloc(p->yystack, newSize*sizeof(pNew[0])); } if( pNew ){ p->yystack = pNew; @@ -1610,7 +1610,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 ) taosMemoryFree(pParser->yystack); #endif } diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 4d80c47ec6..012af26c17 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -65,7 +65,7 @@ private: friend class MockCatalogServiceImpl; static std::unique_ptr createTableBuilder(int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { - STableMeta* meta = (STableMeta*)std::calloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags)); + STableMeta* meta = (STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags)); if (nullptr == meta) { throw std::bad_alloc(); } @@ -277,7 +277,7 @@ private: return TSDB_CODE_TSC_INVALID_TABLE_NAME; } int32_t len = sizeof(STableMeta) + sizeof(SSchema) * (src->tableInfo.numOfTags + src->tableInfo.numOfColumns); - dst->reset((STableMeta*)std::calloc(1, len)); + dst->reset((STableMeta*)taosMemoryCalloc(1, len)); if (!dst) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } diff --git a/source/libs/parser/test/mockCatalogService.h b/source/libs/parser/test/mockCatalogService.h index a722f0b821..887979f11e 100644 --- a/source/libs/parser/test/mockCatalogService.h +++ b/source/libs/parser/test/mockCatalogService.h @@ -44,7 +44,7 @@ public: struct MockTableMeta { ~MockTableMeta() { - free(schema); + taosMemoryFree(schema); } STableMeta* schema; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 7aa58eafb8..1813ad0827 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -99,7 +99,7 @@ private: throw "nodesNodeToString failed!"; } string str(pStr); - tfree(pStr); + taosMemoryFreeClear(pStr); return str; } diff --git a/source/libs/planner/src/planScaleOut.c b/source/libs/planner/src/planScaleOut.c index 6928b1728f..ca6c7a2577 100644 --- a/source/libs/planner/src/planScaleOut.c +++ b/source/libs/planner/src/planScaleOut.c @@ -61,7 +61,7 @@ static int32_t scaleOutForMerge(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, static int32_t doSetScanVgroup(SLogicNode* pNode, const SVgroupInfo* pVgroup, bool* pFound) { if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode)) { SScanLogicNode* pScan = (SScanLogicNode*)pNode; - pScan->pVgroupList = calloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); + pScan->pVgroupList = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); if (NULL == pScan->pVgroupList) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index d203d41cb0..b7a99d365d 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -64,7 +64,7 @@ static int32_t stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan) { } SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode); if (NULL != pSplitNode) { - SStsInfo* pInfo = calloc(1, sizeof(SStsInfo)); + SStsInfo* pInfo = taosMemoryCalloc(1, sizeof(SStsInfo)); CHECK_ALLOC(pInfo, TSDB_CODE_OUT_OF_MEMORY); pInfo->pScan = (SScanLogicNode*)pSplitNode; pInfo->pSubplan = pSubplan; diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index 319e539fa8..b4c0e43a2d 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -138,7 +138,7 @@ private: return string(); } string str(pStr); - tfree(pStr); + taosMemoryFreeClear(pStr); return str; } diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index b4763024dc..20eb49ed33 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -28,7 +28,7 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN); pOut->dbId = usedbRsp->uid; - pOut->dbVgroup = calloc(1, sizeof(SDBVgInfo)); + pOut->dbVgroup = taosMemoryCalloc(1, sizeof(SDBVgInfo)); if (NULL == pOut->dbVgroup) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -151,7 +151,7 @@ PROCESS_USEDB_OVER: if (code != 0) { if (pOut) { if (pOut->dbVgroup) taosHashCleanup(pOut->dbVgroup->vgHash); - tfree(pOut->dbVgroup); + taosMemoryFreeClear(pOut->dbVgroup); } qError("failed to process usedb rsp since %s", terrstr()); } @@ -199,7 +199,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isSuperTable, STabl int32_t total = msg->numOfColumns + msg->numOfTags; int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total; - STableMeta *pTableMeta = calloc(1, metaSize); + STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize); if (NULL == pTableMeta) { qError("calloc size[%d] failed", metaSize); return TSDB_CODE_TSC_OUT_OF_MEMORY; diff --git a/source/libs/qcom/test/queryTest.cpp b/source/libs/qcom/test/queryTest.cpp index 72ce0f7c37..9615557c88 100644 --- a/source/libs/qcom/test/queryTest.cpp +++ b/source/libs/qcom/test/queryTest.cpp @@ -32,13 +32,13 @@ typedef struct SParam { int32_t testPrint(void* p) { SParam* param = (SParam*)p; printf("hello world, %d\n", param->v); - tfree(p); + taosMemoryFreeClear(p); return 0; } int32_t testPrintError(void* p) { SParam* param = (SParam*) p; - tfree(p); + taosMemoryFreeClear(p); return -1; } @@ -61,14 +61,14 @@ int main(int argc, char** argv) { } TEST(testCase, async_task_test) { - SParam* p = (SParam*)calloc(1, sizeof(SParam)); + SParam* p = (SParam*)taosMemoryCalloc(1, sizeof(SParam)); taosAsyncExec(testPrint, p, NULL); taosMsleep(5); } TEST(testCase, many_async_task_test) { for(int32_t i = 0; i < 50; ++i) { - SParam* p = (SParam*) calloc(1, sizeof(SParam)); + SParam* p = (SParam*) taosMemoryCalloc(1, sizeof(SParam)); p->v = i; taosAsyncExec(testPrint, p, NULL); } @@ -78,7 +78,7 @@ TEST(testCase, many_async_task_test) { TEST(testCase, error_in_async_test) { int32_t code = 0; - SParam* p = (SParam*) calloc(1, sizeof(SParam)); + SParam* p = (SParam*) taosMemoryCalloc(1, sizeof(SParam)); taosAsyncExec(testPrintError, p, &code); taosMsleep(1); printf("Error code:%d after asynchronously exec function\n", code); diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index ae2dccfe39..641fe82a85 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -1259,7 +1259,7 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) { return; } - rspList = calloc(schNum, sizeof(SQWHbInfo)); + rspList = taosMemoryCalloc(schNum, sizeof(SQWHbInfo)); if (NULL == rspList) { QW_UNLOCK(QW_READ, &mgmt->schLock); QW_ELOG("calloc %d SQWHbInfo failed", schNum); @@ -1293,7 +1293,7 @@ _return: tFreeSSchedulerHbRsp(&rspList[j].rsp); } - tfree(rspList); + taosMemoryFreeClear(rspList); taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); } @@ -1305,7 +1305,7 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qW } int32_t code = 0; - SQWorkerMgmt *mgmt = calloc(1, sizeof(SQWorkerMgmt)); + SQWorkerMgmt *mgmt = taosMemoryCalloc(1, sizeof(SQWorkerMgmt)); if (NULL == mgmt) { qError("calloc %d failed", (int32_t)sizeof(SQWorkerMgmt)); QW_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1330,7 +1330,7 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qW mgmt->schHash = taosHashInit(mgmt->cfg.maxSchedulerNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); if (NULL == mgmt->schHash) { - tfree(mgmt); + taosMemoryFreeClear(mgmt); qError("init %d scheduler hash failed", mgmt->cfg.maxSchedulerNum); QW_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -1370,7 +1370,7 @@ _return: taosTmrCleanUp(mgmt->timer); - tfree(mgmt); + taosMemoryFreeClear(mgmt); QW_RET(code); } @@ -1389,7 +1389,7 @@ void qWorkerDestroy(void **qWorkerMgmt) { //TODO FREE ALL - tfree(*qWorkerMgmt); + taosMemoryFreeClear(*qWorkerMgmt); } int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRsp **rsp) { @@ -1406,7 +1406,7 @@ int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRs taskNum = taosHashGetSize(sch->tasksHash); int32_t size = sizeof(SSchedulerStatusRsp) + sizeof((*rsp)->status[0]) * taskNum; - *rsp = calloc(1, size); + *rsp = taosMemoryCalloc(1, size); if (NULL == *rsp) { QW_SCH_ELOG("calloc %d failed", size); QW_UNLOCK(QW_READ, &sch->tasksLock); diff --git a/source/libs/qworker/src/qworkerMsg.c b/source/libs/qworker/src/qworkerMsg.c index 79832b4db4..56267c462b 100644 --- a/source/libs/qworker/src/qworkerMsg.c +++ b/source/libs/qworker/src/qworkerMsg.c @@ -167,7 +167,7 @@ int32_t qwBuildAndSendShowRsp(SRpcMsg *pMsg, int32_t code) { SVShowTablesRsp showRsp = {0}; // showRsp.showId = 1; - showRsp.tableMeta.pSchemas = calloc(numOfCols, sizeof(SSchema)); + showRsp.tableMeta.pSchemas = taosMemoryCalloc(numOfCols, sizeof(SSchema)); if (showRsp.tableMeta.pSchemas == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -298,7 +298,7 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { char* sql = strndup(msg->msg, msg->sqlLen); QW_SCH_TASK_DLOG("processQuery start, node:%p, sql:%s", node, sql); - tfree(sql); + taosMemoryFreeClear(sql); QW_ERR_RET(qwProcessQuery(QW_FPARAMS(), &qwMsg, msg->taskType)); diff --git a/source/libs/qworker/test/qworkerTests.cpp b/source/libs/qworker/test/qworkerTests.cpp index 36f1e8d900..705f0e2fbe 100644 --- a/source/libs/qworker/test/qworkerTests.cpp +++ b/source/libs/qworker/test/qworkerTests.cpp @@ -165,7 +165,7 @@ int32_t qwtStringToPlan(const char* str, SSubplan** subplan) { int32_t qwtPutReqToFetchQueue(void *node, struct SRpcMsg *pMsg) { taosWLockLatch(&qwtTestFetchQueueLock); - struct SRpcMsg *newMsg = (struct SRpcMsg *)calloc(1, sizeof(struct SRpcMsg)); + struct SRpcMsg *newMsg = (struct SRpcMsg *)taosMemoryCalloc(1, sizeof(struct SRpcMsg)); memcpy(newMsg, pMsg, sizeof(struct SRpcMsg)); qwtTestFetchQueue[qwtTestFetchQueueWIdx++] = newMsg; if (qwtTestFetchQueueWIdx >= qwtTestFetchQueueSize) { @@ -188,7 +188,7 @@ int32_t qwtPutReqToFetchQueue(void *node, struct SRpcMsg *pMsg) { int32_t qwtPutReqToQueue(void *node, struct SRpcMsg *pMsg) { taosWLockLatch(&qwtTestQueryQueueLock); - struct SRpcMsg *newMsg = (struct SRpcMsg *)calloc(1, sizeof(struct SRpcMsg)); + struct SRpcMsg *newMsg = (struct SRpcMsg *)taosMemoryCalloc(1, sizeof(struct SRpcMsg)); memcpy(newMsg, pMsg, sizeof(struct SRpcMsg)); qwtTestQueryQueue[qwtTestQueryQueueWIdx++] = newMsg; if (qwtTestQueryQueueWIdx >= qwtTestQueryQueueSize) { @@ -312,7 +312,7 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) { } if (endExec) { - *pRes = (SSDataBlock*)calloc(1, sizeof(SSDataBlock)); + *pRes = (SSDataBlock*)taosMemoryCalloc(1, sizeof(SSDataBlock)); (*pRes)->info.rows = taosRand() % 1000 + 1; } else { *pRes = NULL; @@ -336,7 +336,7 @@ int32_t qwtPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* p assert(0); } - free((void *)pInput->pData); + taosMemoryFree((void *)pInput->pData); taosWLockLatch(&qwtTestSinkLock); @@ -763,7 +763,7 @@ void *queryQueueThread(void *param) { assert(0); } - free(queryRpc); + taosMemoryFree(queryRpc); if (qwtTestStop && qwtTestQueryQueueNum <= 0 && qwtTestCaseFinished) { break; @@ -832,7 +832,7 @@ void *fetchQueueThread(void *param) { break; } - free(fetchRpc); + taosMemoryFree(fetchRpc); if (qwtTestStop && qwtTestFetchQueueNum <= 0 && qwtTestCaseFinished) { break; diff --git a/source/libs/scalar/inc/filterInt.h b/source/libs/scalar/inc/filterInt.h index e1ffb2efd1..834a722bd8 100644 --- a/source/libs/scalar/inc/filterInt.h +++ b/source/libs/scalar/inc/filterInt.h @@ -338,7 +338,7 @@ typedef struct SFilterInfo { #define FILTER_PUSH_VAR_HASH(colInfo, ha) do { (colInfo).type = RANGE_TYPE_VAR_HASH; (colInfo).info = ha;} while (0) #define FILTER_PUSH_CTX(colInfo, ctx) do { (colInfo).type = RANGE_TYPE_MR_CTX; (colInfo).info = ctx;} while (0) -#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = malloc(sizeof(uint32_t) * n); memcpy(*(dst), src, sizeof(uint32_t) * n);} while (0) +#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); memcpy(*(dst), src, sizeof(uint32_t) * n);} while (0) #define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) do { if ((gres)->colCtxs == NULL) { (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); } SFilterColCtx cCtx = {idx, ctx}; taosArrayPush((gres)->colCtxs, &cCtx); } while (0) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 58b5c8340a..23e3e352c8 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -297,14 +297,14 @@ static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void int32_t filterInitUnitsFields(SFilterInfo *info) { info->unitSize = FILTER_DEFAULT_UNIT_SIZE; - info->units = calloc(info->unitSize, sizeof(SFilterUnit)); + info->units = taosMemoryCalloc(info->unitSize, sizeof(SFilterUnit)); info->fields[FLD_TYPE_COLUMN].num = 0; info->fields[FLD_TYPE_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; - info->fields[FLD_TYPE_COLUMN].fields = calloc(info->fields[FLD_TYPE_COLUMN].size, sizeof(SFilterField)); + info->fields[FLD_TYPE_COLUMN].fields = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].size, sizeof(SFilterField)); info->fields[FLD_TYPE_VALUE].num = 0; info->fields[FLD_TYPE_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; - info->fields[FLD_TYPE_VALUE].fields = calloc(info->fields[FLD_TYPE_VALUE].size, sizeof(SFilterField)); + info->fields[FLD_TYPE_VALUE].fields = taosMemoryCalloc(info->fields[FLD_TYPE_VALUE].size, sizeof(SFilterField)); return TSDB_CODE_SUCCESS; } @@ -318,7 +318,7 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt r->prev = NULL; r->next = NULL; } else { - r = calloc(1, sizeof(SFilterRangeNode)); + r = taosMemoryCalloc(1, sizeof(SFilterRangeNode)); } FILTER_COPY_RA(&r->ra, ra); @@ -332,7 +332,7 @@ void* filterInitRangeCtx(int32_t type, int32_t options) { return NULL; } - SFilterRangeCtx *ctx = calloc(1, sizeof(SFilterRangeCtx)); + SFilterRangeCtx *ctx = taosMemoryCalloc(1, sizeof(SFilterRangeCtx)); ctx->type = type; ctx->options = options; @@ -748,18 +748,18 @@ int32_t filterFreeRangeCtx(void* h) { while (r) { rn = r->next; - free(r); + taosMemoryFree(r); r = rn; } r = ctx->rf; while (r) { rn = r->next; - free(r); + taosMemoryFree(r); r = rn; } - free(ctx); + taosMemoryFree(ctx); return TSDB_CODE_SUCCESS; } @@ -769,7 +769,7 @@ int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group SFilterGroup gp = {0}; gp.unitNum = gp1->unitNum + gp2->unitNum; - gp.unitIdxs = calloc(gp.unitNum, sizeof(*gp.unitIdxs)); + gp.unitIdxs = taosMemoryCalloc(gp.unitNum, sizeof(*gp.unitIdxs)); memcpy(gp.unitIdxs, gp1->unitIdxs, gp1->unitNum * sizeof(*gp.unitIdxs)); memcpy(gp.unitIdxs + gp1->unitNum, gp2->unitIdxs, gp2->unitNum * sizeof(*gp.unitIdxs)); @@ -849,7 +849,7 @@ int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t d return -1; } -// In the params, we should use void *data instead of void **data, there is no need to use tfree(*data) to set *data = 0 +// In the params, we should use void *data instead of void **data, there is no need to use taosMemoryFreeClear(*data) to set *data = 0 // Besides, fields data value is a pointer, so dataLen should be POINTER_BYTES for better. int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, SFilterFieldId *fid, int32_t dataLen, bool freeIfExists) { int32_t idx = -1; @@ -869,7 +869,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, idx = *num; if (idx >= info->fields[type].size) { info->fields[type].size += FILTER_DEFAULT_FIELD_SIZE; - info->fields[type].fields = realloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField)); + info->fields[type].fields = taosMemoryRealloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField)); } info->fields[type].fields[idx].flag = type; @@ -891,7 +891,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, } } else { if (data && freeIfExists) { - tfree(*data); + taosMemoryFreeClear(*data); } } @@ -954,7 +954,7 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi if (info->unitNum >= info->unitSize) { uint32_t psize = info->unitSize; info->unitSize += FILTER_DEFAULT_UNIT_SIZE; - info->units = realloc(info->units, info->unitSize * sizeof(SFilterUnit)); + info->units = taosMemoryRealloc(info->units, info->unitSize * sizeof(SFilterUnit)); memset(info->units + psize, 0, sizeof(*info->units) * FILTER_DEFAULT_UNIT_SIZE); } @@ -1000,7 +1000,7 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { if (group->unitNum >= group->unitSize) { group->unitSize += FILTER_DEFAULT_UNIT_SIZE; - group->unitIdxs = realloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs)); + group->unitIdxs = taosMemoryRealloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs)); } group->unitIdxs[group->unitNum++] = unitIdx; @@ -1028,12 +1028,12 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { in.type = valueNode->node.resType.type; in.bytes = valueNode->node.resType.bytes; in.data = nodesGetValueFromNode(valueNode); - out.data = malloc(sizeof(int64_t)); + out.data = taosMemoryMalloc(sizeof(int64_t)); code = vectorConvertImpl(&in, &out); if (code) { fltError("convert from %d to %d failed", in.type, out.type); - tfree(out.data); + taosMemoryFreeClear(out.data); FLT_ERR_RET(code); } @@ -1148,17 +1148,17 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if ((!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) && (!FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL))) { __compar_fn_t func = getComparFunc(type, 0); if (func(&ra->s, &ra->e) == 0) { - void *data = malloc(sizeof(int64_t)); + void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, OP_TYPE_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); return TSDB_CODE_SUCCESS; } else { - void *data = malloc(sizeof(int64_t)); + void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - void *data2 = malloc(sizeof(int64_t)); + void *data2 = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data2, &ra->e); filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); @@ -1170,7 +1170,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { - void *data = malloc(sizeof(int64_t)); + void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx); @@ -1178,7 +1178,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } if (!FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { - void *data = malloc(sizeof(int64_t)); + void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->e); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &left, &right, &uidx); @@ -1224,16 +1224,16 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if ((!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) &&(!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL))) { __compar_fn_t func = getComparFunc(type, 0); if (func(&r->ra.s, &r->ra.e) == 0) { - void *data = malloc(sizeof(int64_t)); + void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, OP_TYPE_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } else { - void *data = malloc(sizeof(int64_t)); + void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - void *data2 = malloc(sizeof(int64_t)); + void *data2 = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data2, &r->ra.e); filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); @@ -1250,7 +1250,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } if (!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { - void *data = malloc(sizeof(int64_t)); + void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx); @@ -1258,7 +1258,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } if (!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) { - void *data = malloc(sizeof(int64_t)); + void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.e); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &left, &right, &uidx); @@ -1284,8 +1284,8 @@ static void filterFreeGroup(void *pItem) { } SFilterGroup* p = (SFilterGroup*) pItem; - tfree(p->unitIdxs); - tfree(p->unitFlags); + taosMemoryFreeClear(p->unitIdxs); + taosMemoryFreeClear(p->unitFlags); } @@ -1635,7 +1635,7 @@ void filterFreeGroupCtx(SFilterGroupCtx* gRes) { return; } - tfree(gRes->colIdx); + taosMemoryFreeClear(gRes->colIdx); int16_t i = 0, j = 0; @@ -1648,8 +1648,8 @@ void filterFreeGroupCtx(SFilterGroupCtx* gRes) { ++j; } - tfree(gRes->colInfo); - tfree(gRes); + taosMemoryFreeClear(gRes->colInfo); + taosMemoryFreeClear(gRes); } void filterFreeField(SFilterField* field, int32_t type) { @@ -1661,7 +1661,7 @@ void filterFreeField(SFilterField* field, int32_t type) { if (FILTER_GET_FLAG(field->flag, FLD_DATA_IS_HASH)) { taosHashCleanup(field->data); } else { - tfree(field->data); + taosMemoryFreeClear(field->data); } } } @@ -1676,40 +1676,40 @@ void filterFreeInfo(SFilterInfo *info) { return; } - tfree(info->cunits); - tfree(info->blkUnitRes); - tfree(info->blkUnits); + taosMemoryFreeClear(info->cunits); + taosMemoryFreeClear(info->blkUnitRes); + taosMemoryFreeClear(info->blkUnits); for (int32_t i = 0; i < FLD_TYPE_MAX; ++i) { for (uint32_t f = 0; f < info->fields[i].num; ++f) { filterFreeField(&info->fields[i].fields[f], i); } - tfree(info->fields[i].fields); + taosMemoryFreeClear(info->fields[i].fields); } for (uint32_t i = 0; i < info->groupNum; ++i) { filterFreeGroup(&info->groups[i]); } - tfree(info->groups); + taosMemoryFreeClear(info->groups); - tfree(info->units); + taosMemoryFreeClear(info->units); - tfree(info->unitRes); + taosMemoryFreeClear(info->unitRes); - tfree(info->unitFlags); + taosMemoryFreeClear(info->unitFlags); for (uint32_t i = 0; i < info->colRangeNum; ++i) { filterFreeRangeCtx(info->colRange[i]); } - tfree(info->colRange); + taosMemoryFreeClear(info->colRange); filterFreePCtx(&info->pctx); if (!FILTER_GET_FLAG(info->status, FI_STATUS_CLONED)) { - tfree(info); + taosMemoryFreeClear(info); } } @@ -1775,14 +1775,14 @@ int32_t fltInitValFieldData(SFilterInfo *info) { if (type == TSDB_DATA_TYPE_BINARY) { size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; - fi->data = calloc(1, len + 1 + VARSTR_HEADER_SIZE); + fi->data = taosMemoryCalloc(1, len + 1 + VARSTR_HEADER_SIZE); } else if (type == TSDB_DATA_TYPE_NCHAR) { size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; - fi->data = calloc(1, (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + fi->data = taosMemoryCalloc(1, (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); } else if (type != TSDB_DATA_TYPE_JSON){ if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE /* - fi->data = calloc(dType->bytes, tDataTypes[type].bytes); + fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes); for (int32_t a = 0; a < dType->bytes; ++a) { int64_t *v = taosArrayGet(var->arr, a); assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type); @@ -1790,7 +1790,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { */ continue; } else { - fi->data = calloc(1, sizeof(int64_t)); + fi->data = taosMemoryCalloc(1, sizeof(int64_t)); } } else{ // type == TSDB_DATA_TYPE_JSON // fi->data = null; use fi->desc as data, because json value is variable, so use tVariant (fi->desc) @@ -1998,15 +1998,15 @@ _return: int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t* gResNum) { bool empty = false; - uint32_t *colIdx = malloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t)); + uint32_t *colIdx = taosMemoryMalloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t)); uint32_t colIdxi = 0; uint32_t gResIdx = 0; for (uint32_t i = 0; i < info->groupNum; ++i) { SFilterGroup* g = info->groups + i; - gRes[gResIdx] = calloc(1, sizeof(SFilterGroupCtx)); - gRes[gResIdx]->colInfo = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo)); + gRes[gResIdx] = taosMemoryCalloc(1, sizeof(SFilterGroupCtx)); + gRes[gResIdx]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo)); colIdxi = 0; empty = false; @@ -2058,7 +2058,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t ++gResIdx; } - tfree(colIdx); + taosMemoryFreeClear(colIdx); *gResNum = gResIdx; @@ -2350,12 +2350,12 @@ int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { info->groupNum = (uint32_t)groupSize; if (info->groupNum > 0) { - info->groups = calloc(info->groupNum, sizeof(*info->groups)); + info->groups = taosMemoryCalloc(info->groupNum, sizeof(*info->groups)); } for (size_t i = 0; i < groupSize; ++i) { SFilterGroup *pg = taosArrayGet(group, i); - pg->unitFlags = calloc(pg->unitNum, sizeof(*pg->unitFlags)); + pg->unitFlags = taosMemoryCalloc(pg->unitNum, sizeof(*pg->unitFlags)); info->groups[i] = *pg; } @@ -2435,7 +2435,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ uint32_t *idxs = NULL; uint32_t colNum = 0; SFilterGroupCtx *res = NULL; - uint32_t *idxNum = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); + uint32_t *idxNum = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); for (int32_t i = 0; i < gResNum; ++i) { for (uint32_t m = 0; m < gRes[i]->colNum; ++m) { @@ -2456,7 +2456,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ assert(idxNum[i] == gResNum); if (idxs == NULL) { - idxs = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxs)); + idxs = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxs)); } idxs[colNum++] = i; @@ -2465,7 +2465,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ FLT_CHK_JMP(colNum <= 0); info->colRangeNum = colNum; - info->colRange = calloc(colNum, POINTER_BYTES); + info->colRange = taosMemoryCalloc(colNum, POINTER_BYTES); for (int32_t i = 0; i < gResNum; ++i) { res = gRes[i]; @@ -2512,8 +2512,8 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ } _return: - tfree(idxNum); - tfree(idxs); + taosMemoryFreeClear(idxNum); + taosMemoryFreeClear(idxs); return TSDB_CODE_SUCCESS; } @@ -2533,9 +2533,9 @@ int32_t filterPostProcessRange(SFilterInfo *info) { int32_t filterGenerateComInfo(SFilterInfo *info) { - info->cunits = malloc(info->unitNum * sizeof(*info->cunits)); - info->blkUnitRes = malloc(sizeof(*info->blkUnitRes) * info->unitNum); - info->blkUnits = malloc(sizeof(*info->blkUnits) * (info->unitNum + 1) * info->groupNum); + info->cunits = taosMemoryMalloc(info->unitNum * sizeof(*info->cunits)); + info->blkUnitRes = taosMemoryMalloc(sizeof(*info->blkUnitRes) * info->unitNum); + info->blkUnits = taosMemoryMalloc(sizeof(*info->blkUnits) * (info->unitNum + 1) * info->groupNum); for (uint32_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; @@ -2766,7 +2766,7 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, uint32_t *unitIdx = NULL; if (*p == NULL) { - *p = calloc(numOfRows, sizeof(int8_t)); + *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } for (int32_t i = 0; i < numOfRows; ++i) { @@ -2871,7 +2871,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, } if (*p == NULL) { - *p = calloc(numOfRows, sizeof(int8_t)); + *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } for (int32_t i = 0; i < numOfRows; ++i) { @@ -2905,7 +2905,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows } if (*p == NULL) { - *p = calloc(numOfRows, sizeof(int8_t)); + *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } for (int32_t i = 0; i < numOfRows; ++i) { @@ -2947,7 +2947,7 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SColumnD } if (*p == NULL) { - *p = calloc(numOfRows, sizeof(int8_t)); + *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } for (int32_t i = 0; i < numOfRows; ++i) { @@ -2977,7 +2977,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa } if (*p == NULL) { - *p = calloc(numOfRows, sizeof(int8_t)); + *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } for (int32_t i = 0; i < numOfRows; ++i) { @@ -2991,7 +2991,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa // match/nmatch for nchar type need convert from ucs4 to mbs if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)){ - char *newColData = calloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); + char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); if (len < 0){ qError("castConvert1 taosUcs4ToMbs error"); @@ -2999,7 +2999,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa varDataSetLen(newColData, len); (*p)[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, newColData, info->cunits[uidx].valData); } - tfree(newColData); + taosMemoryFreeClear(newColData); }else{ (*p)[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, info->cunits[uidx].valData); } @@ -3022,7 +3022,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg } if (*p == NULL) { - *p = calloc(numOfRows, sizeof(int8_t)); + *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } for (int32_t i = 0; i < numOfRows; ++i) { @@ -3051,7 +3051,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg (*p)[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); } else { if(cunit->dataType == TSDB_DATA_TYPE_NCHAR && (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)){ - char *newColData = calloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); + char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); if (len < 0){ qError("castConvert1 taosUcs4ToMbs error"); @@ -3059,7 +3059,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg varDataSetLen(newColData, len); (*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, cunit->valData); } - tfree(newColData); + taosMemoryFreeClear(newColData); }else{ (*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); } @@ -3125,7 +3125,7 @@ int32_t filterSetExecFunc(SFilterInfo *info) { int32_t filterPreprocess(SFilterInfo *info) { - SFilterGroupCtx** gRes = calloc(info->groupNum, sizeof(SFilterGroupCtx *)); + SFilterGroupCtx** gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *)); int32_t gResNum = 0; filterMergeGroupUnits(info, gRes, &gResNum); @@ -3161,7 +3161,7 @@ _return: filterFreeGroupCtx(gRes[i]); } - tfree(gRes); + taosMemoryFreeClear(gRes); return TSDB_CODE_SUCCESS; } @@ -3216,8 +3216,8 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) { } } - info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); - info->unitFlags = malloc(info->unitNum * sizeof(*info->unitFlags)); + info->unitRes = taosMemoryMalloc(info->unitNum * sizeof(*info->unitRes)); + info->unitFlags = taosMemoryMalloc(info->unitNum * sizeof(*info->unitFlags)); filterDumpInfoToString(info, "Final", 0); @@ -3418,7 +3418,7 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar SFilterField nfi = {0}; nfi.desc = fi->desc; int32_t bytes = FILTER_GET_COL_FIELD_SIZE(fi); - nfi.data = malloc(rows * bytes); + nfi.data = taosMemoryMalloc(rows * bytes); int32_t bufSize = bytes - VARSTR_HEADER_SIZE; for (int32_t j = 0; j < rows; ++j) { char *src = FILTER_GET_COL_FIELD_DATA(fi, j); @@ -3459,7 +3459,7 @@ int32_t filterFreeNcharColumns(SFilterInfo* info) { SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); if (type == TSDB_DATA_TYPE_NCHAR) { - tfree(fi->data); + taosMemoryFreeClear(fi->data); } } @@ -3634,7 +3634,7 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) } if (*pInfo == NULL) { - *pInfo = calloc(1, sizeof(SFilterInfo)); + *pInfo = taosMemoryCalloc(1, sizeof(SFilterInfo)); if (NULL == *pInfo) { fltError("calloc %d failed", (int32_t)sizeof(SFilterInfo)); FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 8e7eaa0f8c..83902c9df8 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -31,7 +31,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { SScalarParam in = {.num = 1}, out = {.num = 1, .type = type}; int8_t dummy = 0; int32_t bufLen = 60; - out.data = malloc(bufLen); + out.data = taosMemoryMalloc(bufLen); int32_t len = 0; void *buf = NULL; @@ -75,14 +75,14 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { cell = cell->pNext; } - tfree(out.data); + taosMemoryFreeClear(out.data); *data = pObj; return TSDB_CODE_SUCCESS; _return: - tfree(out.data); + taosMemoryFreeClear(out.data); taosHashCleanup(pObj); SCL_RET(code); @@ -98,7 +98,7 @@ FORCE_INLINE bool sclIsNull(SScalarParam* param, int32_t idx) { FORCE_INLINE void sclSetNull(SScalarParam* param, int32_t idx) { if (NULL == param->bitmap) { - param->bitmap = calloc(BitmapLen(param->num), sizeof(char)); + param->bitmap = taosMemoryCalloc(BitmapLen(param->num), sizeof(char)); if (NULL == param->bitmap) { sclError("calloc %d failed", param->num); return; @@ -126,7 +126,7 @@ void sclFreeRes(SHashObj *res) { } void sclFreeParamNoData(SScalarParam *param) { - tfree(param->bitmap); + taosMemoryFreeClear(param->bitmap); } @@ -137,7 +137,7 @@ void sclFreeParam(SScalarParam *param) { if (SCL_DATA_TYPE_DUMMY_HASH == param->type) { taosHashCleanup((SHashObj *)param->orig.data); } else { - tfree(param->orig.data); + taosMemoryFreeClear(param->orig.data); } } } @@ -148,7 +148,7 @@ int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) { return TSDB_CODE_SUCCESS; } - *res = malloc(pNode->node.resType.bytes); + *res = taosMemoryMalloc(pNode->node.resType.bytes); if (NULL == (*res)) { sclError("malloc %d failed", pNode->node.resType.bytes); SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -284,7 +284,7 @@ int32_t sclMoveParamListData(SScalarParam *params, int32_t listNum, int32_t idx) int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarCtx *ctx, int32_t *rowNum) { int32_t code = 0; - SScalarParam *paramList = calloc(pParamList->length, sizeof(SScalarParam)); + SScalarParam *paramList = taosMemoryCalloc(pParamList->length, sizeof(SScalarParam)); if (NULL == paramList) { sclError("calloc %d failed", (int32_t)(pParamList->length * sizeof(SScalarParam))); SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -308,7 +308,7 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC _return: - tfree(paramList); + taosMemoryFreeClear(paramList); SCL_RET(code); } @@ -320,7 +320,7 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - SScalarParam *paramList = calloc(paramNum, sizeof(SScalarParam)); + SScalarParam *paramList = taosMemoryCalloc(paramNum, sizeof(SScalarParam)); if (NULL == paramList) { sclError("calloc %d failed", (int32_t)(paramNum * sizeof(SScalarParam))); SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -337,7 +337,7 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal _return: - tfree(paramList); + taosMemoryFreeClear(paramList); SCL_RET(code); } @@ -360,7 +360,7 @@ int32_t sclExecFuncion(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outpu SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, &rowNum)); output->type = node->node.resType.type; - output->data = calloc(rowNum, sizeof(tDataTypes[output->type].bytes)); + output->data = taosMemoryCalloc(rowNum, sizeof(tDataTypes[output->type].bytes)); if (NULL == output->data) { sclError("calloc %d failed", (int32_t)(rowNum * sizeof(tDataTypes[output->type].bytes))); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -384,7 +384,7 @@ _return: sclFreeParamNoData(params + i); } - tfree(params); + taosMemoryFreeClear(params); SCL_RET(code); } @@ -415,7 +415,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o output->type = node->node.resType.type; output->bytes = sizeof(bool); output->num = rowNum; - output->data = calloc(rowNum, sizeof(bool)); + output->data = taosMemoryCalloc(rowNum, sizeof(bool)); if (NULL == output->data) { sclError("calloc %d failed", (int32_t)(rowNum * sizeof(bool))); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -449,7 +449,7 @@ _return: sclFreeParamNoData(params + i); } - tfree(params); + taosMemoryFreeClear(params); SCL_RET(code); } @@ -463,7 +463,7 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp output->type = node->node.resType.type; output->num = rowNum; output->bytes = tDataTypes[output->type].bytes; - output->data = calloc(rowNum, tDataTypes[output->type].bytes); + output->data = taosMemoryCalloc(rowNum, tDataTypes[output->type].bytes); if (NULL == output->data) { sclError("calloc %d failed", (int32_t)rowNum * tDataTypes[output->type].bytes); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -485,7 +485,7 @@ _return: sclFreeParamNoData(params + i); } - tfree(params); + taosMemoryFreeClear(params); SCL_RET(code); } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index fd900afcda..9ae118607e 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -169,7 +169,7 @@ static void tconcat(SScalarParam* pOutput, size_t numOfInput, const SScalarParam } } - pOutput->data = realloc(pOutput->data, rowLen * num); + pOutput->data = taosMemoryRealloc(pOutput->data, rowLen * num); assert(pOutput->data); char* rstart = pOutput->data; @@ -284,13 +284,13 @@ int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncPa SScalarFuncParam rightOutput = {0}; if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) { - leftOutput.data = malloc(sizeof(int64_t) * numOfRows); + leftOutput.data = taosMemoryMalloc(sizeof(int64_t) * numOfRows); evaluateExprNodeTree(pLeft, numOfRows, &leftOutput, param, getSourceDataBlock); } // the right output has result from the right child syntax tree if (pRight->nodeType == TEXPR_BINARYEXPR_NODE || pRight->nodeType == TEXPR_UNARYEXPR_NODE) { - rightOutput.data = malloc(sizeof(int64_t) * numOfRows); + rightOutput.data = taosMemoryMalloc(sizeof(int64_t) * numOfRows); evaluateExprNodeTree(pRight, numOfRows, &rightOutput, param, getSourceDataBlock); } @@ -322,7 +322,7 @@ int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncPa void* outputBuf = pOutput->data; if (isStringOp(pExprs->_node.optr)) { - outputBuf = realloc(pOutput->data, (left.bytes + right.bytes) * left.num); + outputBuf = taosMemoryRealloc(pOutput->data, (left.bytes + right.bytes) * left.num); } OperatorFn(&left, &right, outputBuf, TSDB_ORDER_ASC); @@ -345,7 +345,7 @@ int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncPa // reserve enough memory buffer if (isBinaryStringOp(pExprs->_node.optr)) { - void* outputBuf = realloc(pOutput->data, left.bytes * left.num); + void* outputBuf = taosMemoryRealloc(pOutput->data, left.bytes * left.num); assert(outputBuf != NULL); pOutput->data = outputBuf; } @@ -353,8 +353,8 @@ int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncPa OperatorFn(&left, pOutput); } - tfree(leftOutput.data); - tfree(rightOutput.data); + taosMemoryFreeClear(leftOutput.data); + taosMemoryFreeClear(rightOutput.data); return 0; } @@ -379,13 +379,13 @@ void setScalarFunctionSupp(struct SScalarFunctionSupport* sas, SExprInfo *pExprI return; } - sas->colList = calloc(1, pSDataBlock->info.numOfCols*sizeof(SColumnInfo)); + sas->colList = taosMemoryCalloc(1, pSDataBlock->info.numOfCols*sizeof(SColumnInfo)); for(int32_t i = 0; i < sas->numOfCols; ++i) { SColumnInfoData* pColData = taosArrayGet(pSDataBlock->pDataBlock, i); sas->colList[i] = pColData->info; } - sas->data = calloc(sas->numOfCols, POINTER_BYTES); + sas->data = taosMemoryCalloc(sas->numOfCols, POINTER_BYTES); // set the input column data for (int32_t f = 0; f < pSDataBlock->info.numOfCols; ++f) { @@ -395,7 +395,7 @@ void setScalarFunctionSupp(struct SScalarFunctionSupport* sas, SExprInfo *pExprI } SScalarFunctionSupport* createScalarFuncSupport(int32_t num) { - SScalarFunctionSupport* pSupp = calloc(num, sizeof(SScalarFunctionSupport)); + SScalarFunctionSupport* pSupp = taosMemoryCalloc(num, sizeof(SScalarFunctionSupport)); return pSupp; } @@ -406,9 +406,9 @@ void destroyScalarFuncSupport(struct SScalarFunctionSupport* pSupport, int32_t n for(int32_t i = 0; i < num; ++i) { SScalarFunctionSupport* pSupp = &pSupport[i]; - tfree(pSupp->data); - tfree(pSupp->colList); + taosMemoryFreeClear(pSupp->data); + taosMemoryFreeClear(pSupp->colList); } - tfree(pSupport); + taosMemoryFreeClear(pSupport); } \ No newline at end of file diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 17ac9b19fd..2300f5a1d3 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -305,7 +305,7 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t if (TSDB_DATA_TYPE_BINARY == inType) { if (varDataLen(pIn->data) >= bufSize) { bufSize = varDataLen(pIn->data) + 1; - tmp = realloc(tmp, bufSize); + tmp = taosMemoryRealloc(tmp, bufSize); } memcpy(tmp, varDataVal(pIn->data), varDataLen(pIn->data)); @@ -313,13 +313,13 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t } else { if (varDataLen(pIn->data) * TSDB_NCHAR_SIZE >= bufSize) { bufSize = varDataLen(pIn->data) * TSDB_NCHAR_SIZE + 1; - tmp = realloc(tmp, bufSize); + tmp = taosMemoryRealloc(tmp, bufSize); } int len = taosUcs4ToMbs((TdUcs4*)varDataVal(pIn->data), varDataLen(pIn->data), tmp); if (len < 0){ sclError("castConvert taosUcs4ToMbs error 1"); - tfree(tmp); + taosMemoryFreeClear(tmp); return TSDB_CODE_QRY_APP_ERROR; } @@ -329,7 +329,7 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t (*func)(tmp, pOut, outType); } - tfree(tmp); + taosMemoryFreeClear(tmp); return TSDB_CODE_SUCCESS; } @@ -480,7 +480,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p paramOut1->bytes = param1->bytes; paramOut1->type = type; paramOut1->num = param1->num; - paramOut1->data = malloc(paramOut1->num * tDataTypes[paramOut1->type].bytes); + paramOut1->data = taosMemoryMalloc(paramOut1->num * tDataTypes[paramOut1->type].bytes); if (NULL == paramOut1->data) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -488,7 +488,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p code = vectorConvertImpl(param1, paramOut1); if (code) { - tfree(paramOut1->data); + taosMemoryFreeClear(paramOut1->data); return code; } } @@ -497,17 +497,17 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p paramOut2->bytes = param2->bytes; paramOut2->type = type; paramOut2->num = param2->num; - paramOut2->data = malloc(paramOut2->num * tDataTypes[paramOut2->type].bytes); + paramOut2->data = taosMemoryMalloc(paramOut2->num * tDataTypes[paramOut2->type].bytes); if (NULL == paramOut2->data) { - tfree(paramOut1->data); + taosMemoryFreeClear(paramOut1->data); return TSDB_CODE_QRY_OUT_OF_MEMORY; } paramOut2->orig.data = paramOut2->data; code = vectorConvertImpl(param2, paramOut2); if (code) { - tfree(paramOut1->data); - tfree(paramOut2->data); + taosMemoryFreeClear(paramOut1->data); + taosMemoryFreeClear(paramOut2->data); return code; } } @@ -523,7 +523,7 @@ void vectorMath(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, i SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false}; SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false}; if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(double)); + leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; @@ -536,7 +536,7 @@ void vectorMath(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, i pLeft = &leftParam; } if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(double)); + rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); sclFreeParam(&leftParam); @@ -681,7 +681,7 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false}; SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false}; if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(double)); + leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; @@ -694,7 +694,7 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in pLeft = &leftParam; } if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(double)); + rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); sclFreeParam(&leftParam); @@ -774,7 +774,7 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(double)); + leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; @@ -787,7 +787,7 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in pLeft = &leftParam; } if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(double)); + rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); sclFreeParam(&leftParam); @@ -863,7 +863,7 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(double)); + leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; @@ -876,7 +876,7 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu pLeft = &leftParam; } if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(double)); + rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); sclFreeParam(&leftParam); @@ -953,7 +953,7 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(double)); + leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; @@ -966,7 +966,7 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, pLeft = &leftParam; } if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(double)); + rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); sclFreeParam(&leftParam); @@ -1040,7 +1040,7 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(double)); + leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; @@ -1053,7 +1053,7 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO pLeft = &leftParam; } if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(double)); + rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); sclFreeParam(&leftParam); @@ -1206,7 +1206,7 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, SScalarParam leftParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pLeft->num}; SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num}; if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(int64_t)); + leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(int64_t)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; @@ -1219,7 +1219,7 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, pLeft = &leftParam; } if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(int64_t)); + rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(int64_t)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); sclFreeParam(&leftParam); @@ -1303,7 +1303,7 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, SScalarParam leftParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pLeft->num}; SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num}; if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(int64_t)); + leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(int64_t)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; @@ -1316,7 +1316,7 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, pLeft = &leftParam; } if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(int64_t)); + rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(int64_t)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); sclFreeParam(&leftParam); diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index 328028a1d4..54f82eae2d 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -71,7 +71,7 @@ void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) { vnode->node.resType.type = dataType; if (IS_VAR_DATA_TYPE(dataType)) { - vnode->datum.p = (char *)malloc(varDataTLen(value)); + vnode->datum.p = (char *)taosMemoryMalloc(varDataTLen(value)); varDataCopy(vnode->datum.p, value); vnode->node.resType.bytes = varDataLen(value); } else { @@ -102,7 +102,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in } if (NULL == *block) { - SSDataBlock *res = (SSDataBlock *)calloc(1, sizeof(SSDataBlock)); + SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); res->info.numOfCols = 3; res->info.rows = rowNum; res->pDataBlock = taosArrayInit(3, sizeof(SColumnInfoData)); @@ -113,7 +113,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in idata.info.colId = i + 1; int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)calloc(1, size); + idata.pData = (char *)taosMemoryCalloc(1, size); taosArrayPush(res->pDataBlock, &idata); } @@ -122,7 +122,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in idata.info.bytes = dataBytes; idata.info.colId = 3; int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)calloc(1, size); + idata.pData = (char *)taosMemoryCalloc(1, size); taosArrayPush(res->pDataBlock, &idata); blockDataEnsureCapacity(res, rowNum); @@ -150,7 +150,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in idata.info.bytes = dataBytes; idata.info.colId = 1 + idx; int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)calloc(1, size); + idata.pData = (char *)taosMemoryCalloc(1, size); taosArrayPush(res->pDataBlock, &idata); res->info.numOfCols++; SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); @@ -325,7 +325,7 @@ TEST(columnTest, smallint_column_greater_double_value) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); blockDataDestroy(src); nodesDestroyNode(opNode); @@ -380,7 +380,7 @@ TEST(columnTest, int_column_greater_smallint_value) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -426,7 +426,7 @@ TEST(columnTest, int_column_in_double_list) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -491,7 +491,7 @@ TEST(columnTest, binary_column_in_binary_list) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -540,7 +540,7 @@ TEST(columnTest, binary_column_like_binary) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -588,7 +588,7 @@ TEST(columnTest, binary_column_is_null) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -635,7 +635,7 @@ TEST(columnTest, binary_column_is_not_null) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -674,7 +674,7 @@ TEST(opTest, smallint_column_greater_int_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -713,7 +713,7 @@ TEST(opTest, smallint_value_add_int_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -758,7 +758,7 @@ TEST(opTest, bigint_column_multi_binary_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -801,7 +801,7 @@ TEST(opTest, smallint_column_and_binary_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -839,7 +839,7 @@ TEST(opTest, smallint_column_or_float_column) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -879,7 +879,7 @@ TEST(opTest, smallint_column_or_double_value) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -924,7 +924,7 @@ TEST(opTest, binary_column_is_true) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(opNode); blockDataDestroy(src); @@ -996,7 +996,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(logicNode1); blockDataDestroy(src); @@ -1065,7 +1065,7 @@ TEST(filterModelogicTest, same_column_and_or_and) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(logicNode1); blockDataDestroy(src); @@ -1135,7 +1135,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(logicNode1); blockDataDestroy(src); @@ -1204,7 +1204,7 @@ TEST(filterModelogicTest, same_column_or_and_or) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(logicNode1); blockDataDestroy(src); @@ -1277,7 +1277,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } - tfree(rowRes); + taosMemoryFreeClear(rowRes); filterFreeInfo(filter); nodesDestroyNode(logicNode1); blockDataDestroy(src); diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index d6a73d99bb..dfa141d706 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -71,7 +71,7 @@ void scltInitLogFile() { void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *slotId, bool newBlock, int32_t rows, SColumnInfo *colInfo) { if (newBlock) { - SSDataBlock *res = (SSDataBlock *)calloc(1, sizeof(SSDataBlock)); + SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); res->info.numOfCols = 1; res->info.rows = rows; res->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); @@ -106,7 +106,7 @@ void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) { vnode->node.resType.type = dataType; if (IS_VAR_DATA_TYPE(dataType)) { - vnode->datum.p = (char *)malloc(varDataTLen(value)); + vnode->datum.p = (char *)taosMemoryMalloc(varDataTLen(value)); varDataCopy(vnode->datum.p, value); vnode->node.resType.bytes = varDataTLen(value); } else { @@ -125,7 +125,7 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in rnode->dataBlockId = 0; if (NULL == *block) { - SSDataBlock *res = (SSDataBlock *)calloc(1, sizeof(SSDataBlock)); + SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); res->info.numOfCols = 3; res->info.rows = rowNum; res->pDataBlock = taosArrayInit(3, sizeof(SColumnInfoData)); @@ -136,7 +136,7 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in idata.info.colId = i + 1; int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)calloc(1, size); + idata.pData = (char *)taosMemoryCalloc(1, size); taosArrayPush(res->pDataBlock, &idata); } @@ -145,7 +145,7 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in idata.info.bytes = dataBytes; idata.info.colId = 3; int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)calloc(1, size); + idata.pData = (char *)taosMemoryCalloc(1, size); taosArrayPush(res->pDataBlock, &idata); blockDataEnsureCapacity(res, rowNum); @@ -173,7 +173,7 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in idata.info.bytes = dataBytes; idata.info.colId = 1 + idx; int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)calloc(1, size); + idata.pData = (char *)taosMemoryCalloc(1, size); taosArrayPush(res->pDataBlock, &idata); res->info.numOfCols++; SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index fe102ed6ed..9e120041af 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -70,7 +70,7 @@ void schFreeTask(SSchTask *pTask) { taosArrayDestroy(pTask->candidateAddrs); } - tfree(pTask->msg); + taosMemoryFreeClear(pTask->msg); if (pTask->children) { taosArrayDestroy(pTask->children); @@ -1019,7 +1019,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch if (pJob->resData) { SCH_TASK_ELOG("got fetch rsp while res already exists, res:%p", pJob->resData); - tfree(rsp); + taosMemoryFreeClear(rsp); SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); } @@ -1089,7 +1089,7 @@ _return: schReleaseJob(pParam->refId); } - tfree(param); + taosMemoryFreeClear(param); SCH_RET(code); } @@ -1203,13 +1203,13 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet SSchTrans *trans = (SSchTrans *)transport; - SMsgSendInfo *pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); + SMsgSendInfo *pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == pMsgSendInfo) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo)); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SSchCallbackParam *param = calloc(1, sizeof(SSchCallbackParam)); + SSchCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchCallbackParam)); if (NULL == param) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchCallbackParam)); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1241,8 +1241,8 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet _return: - tfree(param); - tfree(pMsgSendInfo); + taosMemoryFreeClear(param); + taosMemoryFreeClear(pMsgSendInfo); SCH_RET(code); } @@ -1262,7 +1262,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, case TDMT_VND_CREATE_TABLE: case TDMT_VND_SUBMIT: { msgSize = pTask->msgLen; - msg = calloc(1, msgSize); + msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1276,7 +1276,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, uint32_t len = strlen(pJob->sql); msgSize = sizeof(SSubQueryMsg) + pTask->msgLen + len; - msg = calloc(1, msgSize); + msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1300,7 +1300,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, case TDMT_VND_RES_READY: { msgSize = sizeof(SResReadyReq); - msg = calloc(1, msgSize); + msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1317,7 +1317,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, } case TDMT_VND_FETCH: { msgSize = sizeof(SResFetchReq); - msg = calloc(1, msgSize); + msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1334,7 +1334,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, } case TDMT_VND_DROP_TASK: { msgSize = sizeof(STaskDropReq); - msg = calloc(1, msgSize); + msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1362,7 +1362,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, SCH_JOB_ELOG("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - msg = calloc(1, msgSize); + msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_JOB_ELOG("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1394,7 +1394,7 @@ _return: SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); - tfree(msg); + taosMemoryFreeClear(msg); SCH_RET(code); } @@ -1588,8 +1588,8 @@ void schFreeJobImpl(void *job) { taosArrayDestroy(pJob->levels); taosArrayDestroy(pJob->nodeList); - tfree(pJob->resData); - tfree(pJob); + taosMemoryFreeClear(pJob->resData); + taosMemoryFreeClear(pJob); qDebug("QID:0x%" PRIx64 " job freed, refId:%" PRIx64 ", pointer:%p", queryId, refId, pJob); } @@ -1603,7 +1603,7 @@ static int32_t schExecJobImpl(void *transport, SArray *pNodeList, SQueryPlan *pD } int32_t code = 0; - SSchJob *pJob = calloc(1, sizeof(SSchJob)); + SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob)); if (NULL == pJob) { qError("QID:%" PRIx64 " calloc %d failed", pDag->queryId, (int32_t)sizeof(SSchJob)); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1790,7 +1790,7 @@ int32_t schedulerConvertDagToTaskList(SQueryPlan* pDag, SArray **pTasks) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SSubQueryMsg* pMsg = calloc(1, msgSize); + SSubQueryMsg* pMsg = taosMemoryCalloc(1, msgSize); pMsg->header.vgId = tInfo.addr.nodeId; @@ -1807,7 +1807,7 @@ int32_t schedulerConvertDagToTaskList(SQueryPlan* pDag, SArray **pTasks) { if (NULL == taosArrayPush(info, &tInfo)) { qError("taosArrayPush failed, idx:%d", i); - free(msg); + taosMemoryFree(msg); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } } @@ -1839,7 +1839,7 @@ int32_t schedulerCopyTask(STaskInfo *src, SArray **dst, int32_t copyNum) { info.addr = src->addr; for (int32_t i = 0; i < copyNum; ++i) { - info.msg = malloc(msgSize); + info.msg = taosMemoryMalloc(msgSize); if (NULL == info.msg) { qError("malloc %d failed", msgSize); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1851,7 +1851,7 @@ int32_t schedulerCopyTask(STaskInfo *src, SArray **dst, int32_t copyNum) { if (NULL == taosArrayPush(*dst, &info)) { qError("taosArrayPush failed, idx:%d", i); - free(info.msg); + taosMemoryFree(info.msg); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } } @@ -1931,7 +1931,7 @@ int32_t schedulerFetchRows(int64_t job, void **pData) { } if (NULL == *pData) { - SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)calloc(1, sizeof(SRetrieveTableRsp)); + SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp)); if (rsp) { rsp->completed = 1; } @@ -1993,7 +1993,7 @@ void schedulerFreeTaskList(SArray *taskList) { int32_t taskNum = taosArrayGetSize(taskList); for (int32_t i = 0; i < taskNum; ++i) { STaskInfo *info = taosArrayGet(taskList, i); - tfree(info->msg); + taosMemoryFreeClear(info->msg); } taosArrayDestroy(taskList); diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index b5bd68ba86..b2fbf33b8a 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -95,8 +95,8 @@ void schtBuildQueryDag(SQueryPlan *dag) { SNodeListNode *scan = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); SNodeListNode *merge = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - SSubplan *scanPlan = (SSubplan *)calloc(1, sizeof(SSubplan)); - SSubplan *mergePlan = (SSubplan *)calloc(1, sizeof(SSubplan)); + SSubplan *scanPlan = (SSubplan *)taosMemoryCalloc(1, sizeof(SSubplan)); + SSubplan *mergePlan = (SSubplan *)taosMemoryCalloc(1, sizeof(SSubplan)); scanPlan->id.queryId = qId; scanPlan->id.groupId = 0x0000000000000002; @@ -110,7 +110,7 @@ void schtBuildQueryDag(SQueryPlan *dag) { scanPlan->pChildren = NULL; scanPlan->level = 1; scanPlan->pParents = nodesMakeList(); - scanPlan->pNode = (SPhysiNode*)calloc(1, sizeof(SPhysiNode)); + scanPlan->pNode = (SPhysiNode*)taosMemoryCalloc(1, sizeof(SPhysiNode)); scanPlan->msgType = TDMT_VND_QUERY; mergePlan->id.queryId = qId; @@ -122,7 +122,7 @@ void schtBuildQueryDag(SQueryPlan *dag) { mergePlan->pChildren = nodesMakeList(); mergePlan->pParents = NULL; - mergePlan->pNode = (SPhysiNode*)calloc(1, sizeof(SPhysiNode)); + mergePlan->pNode = (SPhysiNode*)taosMemoryCalloc(1, sizeof(SPhysiNode)); mergePlan->msgType = TDMT_VND_QUERY; merge->pNodeList = nodesMakeList(); @@ -148,8 +148,8 @@ void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) { SNodeListNode *scan = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); SNodeListNode *merge = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - SSubplan *scanPlan = (SSubplan *)calloc(scanPlanNum, sizeof(SSubplan)); - SSubplan *mergePlan = (SSubplan *)calloc(1, sizeof(SSubplan)); + SSubplan *scanPlan = (SSubplan *)taosMemoryCalloc(scanPlanNum, sizeof(SSubplan)); + SSubplan *mergePlan = (SSubplan *)taosMemoryCalloc(1, sizeof(SSubplan)); merge->pNodeList = nodesMakeList(); scan->pNodeList = nodesMakeList(); @@ -173,7 +173,7 @@ void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) { scanPlan[i].pChildren = NULL; scanPlan[i].level = 1; scanPlan[i].pParents = nodesMakeList(); - scanPlan[i].pNode = (SPhysiNode*)calloc(1, sizeof(SPhysiNode)); + scanPlan[i].pNode = (SPhysiNode*)taosMemoryCalloc(1, sizeof(SPhysiNode)); scanPlan[i].msgType = TDMT_VND_QUERY; nodesListAppend(scanPlan[i].pParents, (SNode*)mergePlan); @@ -190,7 +190,7 @@ void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) { mergePlan->execNode.epSet.numOfEps = 0; mergePlan->pParents = NULL; - mergePlan->pNode = (SPhysiNode*)calloc(1, sizeof(SPhysiNode)); + mergePlan->pNode = (SPhysiNode*)taosMemoryCalloc(1, sizeof(SPhysiNode)); mergePlan->msgType = TDMT_VND_QUERY; nodesListAppend(merge->pNodeList, (SNode*)mergePlan); @@ -213,7 +213,7 @@ void schtBuildInsertDag(SQueryPlan *dag) { dag->pSubplans = nodesMakeList(); SNodeListNode *inserta = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - SSubplan *insertPlan = (SSubplan *)calloc(2, sizeof(SSubplan)); + SSubplan *insertPlan = (SSubplan *)taosMemoryCalloc(2, sizeof(SSubplan)); insertPlan[0].id.queryId = qId; insertPlan[0].id.groupId = 0x0000000000000003; @@ -228,7 +228,7 @@ void schtBuildInsertDag(SQueryPlan *dag) { insertPlan[0].pChildren = NULL; insertPlan[0].pParents = NULL; insertPlan[0].pNode = NULL; - insertPlan[0].pDataSink = (SDataSinkNode*)calloc(1, sizeof(SDataSinkNode)); + insertPlan[0].pDataSink = (SDataSinkNode*)taosMemoryCalloc(1, sizeof(SDataSinkNode)); insertPlan[0].msgType = TDMT_VND_SUBMIT; insertPlan[1].id.queryId = qId; @@ -244,7 +244,7 @@ void schtBuildInsertDag(SQueryPlan *dag) { insertPlan[1].pChildren = NULL; insertPlan[1].pParents = NULL; insertPlan[1].pNode = NULL; - insertPlan[1].pDataSink = (SDataSinkNode*)calloc(1, sizeof(SDataSinkNode)); + insertPlan[1].pDataSink = (SDataSinkNode*)taosMemoryCalloc(1, sizeof(SDataSinkNode)); insertPlan[1].msgType = TDMT_VND_SUBMIT; inserta->pNodeList = nodesMakeList(); @@ -258,7 +258,7 @@ void schtBuildInsertDag(SQueryPlan *dag) { int32_t schtPlanToString(const SSubplan *subplan, char** str, int32_t* len) { - *str = (char *)calloc(1, 20); + *str = (char *)taosMemoryCalloc(1, 20); *len = 20; return 0; } @@ -312,9 +312,9 @@ void schtSetRpcSendRequest() { int32_t schtAsyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, SMsgSendInfo* pInfo) { if (pInfo) { - tfree(pInfo->param); - tfree(pInfo->msgInfo.pData); - free(pInfo); + taosMemoryFreeClear(pInfo->param); + taosMemoryFreeClear(pInfo->msgInfo.pData); + taosMemoryFree(pInfo); } return 0; } @@ -373,7 +373,7 @@ void *schtCreateFetchRspThread(void *param) { taosSsleep(1); int32_t code = 0; - SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)calloc(1, sizeof(SRetrieveTableRsp)); + SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp)); rsp->completed = 1; rsp->numOfRows = 10; @@ -396,13 +396,13 @@ void *schtFetchRspThread(void *aa) { taosUsleep(1); - param = (SSchCallbackParam *)calloc(1, sizeof(*param)); + param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param)); param->queryId = schtQueryId; param->taskId = schtFetchTaskId; int32_t code = 0; - SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)calloc(1, sizeof(SRetrieveTableRsp)); + SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp)); rsp->completed = 1; rsp->numOfRows = 10; @@ -484,7 +484,7 @@ void* schtRunJobThread(void *aa) { pIter = taosHashIterate(pJob->execTasks, pIter); } - param = (SSchCallbackParam *)calloc(1, sizeof(*param)); + param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param)); param->refId = queryJobRefId; param->queryId = pJob->queryId; @@ -504,7 +504,7 @@ void* schtRunJobThread(void *aa) { } - param = (SSchCallbackParam *)calloc(1, sizeof(*param)); + param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param)); param->refId = queryJobRefId; param->queryId = pJob->queryId; @@ -524,7 +524,7 @@ void* schtRunJobThread(void *aa) { } - param = (SSchCallbackParam *)calloc(1, sizeof(*param)); + param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param)); param->refId = queryJobRefId; param->queryId = pJob->queryId; @@ -544,7 +544,7 @@ void* schtRunJobThread(void *aa) { } - param = (SSchCallbackParam *)calloc(1, sizeof(*param)); + param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param)); param->refId = queryJobRefId; param->queryId = pJob->queryId; @@ -697,7 +697,7 @@ TEST(queryTest, normalCase) { SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data; ASSERT_EQ(pRsp->completed, 1); ASSERT_EQ(pRsp->numOfRows, 10); - tfree(data); + taosMemoryFreeClear(data); data = NULL; code = schedulerFetchRows(job, &data); @@ -793,7 +793,7 @@ TEST(queryTest, flowCtrlCase) { SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data; ASSERT_EQ(pRsp->completed, 1); ASSERT_EQ(pRsp->numOfRows, 10); - tfree(data); + taosMemoryFreeClear(data); data = NULL; code = schedulerFetchRows(job, &data); diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 0cc4da2bd1..0911dc52aa 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -145,7 +145,7 @@ void* tDecodeSStreamTaskExecReq(const void* buf, SStreamTaskExecReq* pReq) { void tFreeSStreamTaskExecReq(SStreamTaskExecReq* pReq) { taosArrayDestroy(pReq->data); } SStreamTask* tNewSStreamTask(int64_t streamId) { - SStreamTask* pTask = (SStreamTask*)calloc(1, sizeof(SStreamTask)); + SStreamTask* pTask = (SStreamTask*)taosMemoryCalloc(1, sizeof(SStreamTask)); if (pTask == NULL) { return NULL; } @@ -227,9 +227,9 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { void tFreeSStreamTask(SStreamTask* pTask) { // TODO - /*free(pTask->qmsg);*/ - /*free(pTask->executor);*/ - /*free(pTask);*/ + /*taosMemoryFree(pTask->qmsg);*/ + /*taosMemoryFree(pTask->executor);*/ + /*taosMemoryFree(pTask);*/ } #if 0 diff --git a/source/libs/sync/src/syncEnv.c b/source/libs/sync/src/syncEnv.c index d47a525e25..726ebdae07 100644 --- a/source/libs/sync/src/syncEnv.c +++ b/source/libs/sync/src/syncEnv.c @@ -74,7 +74,7 @@ static void syncEnvTick(void *param, void *tmrId) { } static SSyncEnv *doSyncEnvStart() { - SSyncEnv *pSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv)); + SSyncEnv *pSyncEnv = (SSyncEnv *)taosMemoryMalloc(sizeof(SSyncEnv)); assert(pSyncEnv != NULL); memset(pSyncEnv, 0, sizeof(SSyncEnv)); diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index da54aa9668..717b1cc756 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -121,7 +121,7 @@ int32_t syncIOPingTimerStop() { // local function ------------ static SSyncIO *syncIOCreate(char *host, uint16_t port) { - SSyncIO *io = (SSyncIO *)malloc(sizeof(SSyncIO)); + SSyncIO *io = (SSyncIO *)taosMemoryMalloc(sizeof(SSyncIO)); memset(io, 0, sizeof(*io)); io->pMsgQ = taosOpenQueue(); diff --git a/source/libs/sync/src/syncIndexMgr.c b/source/libs/sync/src/syncIndexMgr.c index aa97104180..d33075054a 100644 --- a/source/libs/sync/src/syncIndexMgr.c +++ b/source/libs/sync/src/syncIndexMgr.c @@ -19,7 +19,7 @@ // SMatchIndex ----------------------------- SSyncIndexMgr *syncIndexMgrCreate(SSyncNode *pSyncNode) { - SSyncIndexMgr *pSyncIndexMgr = malloc(sizeof(SSyncIndexMgr)); + SSyncIndexMgr *pSyncIndexMgr = taosMemoryMalloc(sizeof(SSyncIndexMgr)); assert(pSyncIndexMgr != NULL); memset(pSyncIndexMgr, 0, sizeof(SSyncIndexMgr)); @@ -33,7 +33,7 @@ SSyncIndexMgr *syncIndexMgrCreate(SSyncNode *pSyncNode) { void syncIndexMgrDestroy(SSyncIndexMgr *pSyncIndexMgr) { if (pSyncIndexMgr != NULL) { - free(pSyncIndexMgr); + taosMemoryFree(pSyncIndexMgr); } } @@ -78,12 +78,12 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) { cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pSyncIndexMgr->replicas))[i])); } int respondNum = 0; - int *arr = (int *)malloc(sizeof(int) * pSyncIndexMgr->replicaNum); + int *arr = (int *)taosMemoryMalloc(sizeof(int) * pSyncIndexMgr->replicaNum); for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) { arr[i] = pSyncIndexMgr->index[i]; } cJSON *pIndex = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum); - free(arr); + taosMemoryFree(arr); cJSON_AddItemToObject(pRoot, "index", pIndex); snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode); cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); @@ -106,24 +106,24 @@ void syncIndexMgrPrint(SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); printf("syncIndexMgrPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); printf("syncIndexMgrPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncIndexMgrLog(SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); sTrace("syncIndexMgrLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); sTrace("syncIndexMgrLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } \ No newline at end of file diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 58e02b3866..78e454309a 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -151,7 +151,7 @@ int32_t syncPropose2(int64_t rid, const SRpcMsg* pMsg, bool isWeak, uint64_t seq // open/close -------------- SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { - SSyncNode* pSyncNode = (SSyncNode*)malloc(sizeof(SSyncNode)); + SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(SSyncNode)); assert(pSyncNode != NULL); memset(pSyncNode, 0, sizeof(SSyncNode)); @@ -310,7 +310,7 @@ void syncNodeClose(SSyncNode* pSyncNode) { syncNodeStopElectTimer(pSyncNode); syncNodeStopHeartbeatTimer(pSyncNode); - free(pSyncNode); + taosMemoryFree(pSyncNode); } // ping -------------- @@ -723,26 +723,26 @@ void syncNodePrint(SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); printf("syncNodePrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncNodePrint2(char* s, SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); printf("syncNodePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncNodeLog(SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); sTrace("syncNodeLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncNodeLog2(char* s, SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); sTrace("syncNodeLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ------ local funciton --------- @@ -828,7 +828,7 @@ static int32_t syncNodeEqNoop(SSyncNode* ths) { syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg); ths->FpEqMsg(ths->queue, &rpcMsg); - free(serialized); + taosMemoryFree(serialized); syncClientRequestDestroy(pSyncMsg); return ret; @@ -928,5 +928,5 @@ static void syncFreeNode(void* param) { SSyncNode* pNode = param; syncNodePrint2((char*)"==syncFreeNode==", pNode); - free(pNode); + taosMemoryFree(pNode); } \ No newline at end of file diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index f2344c6b6d..5dca165455 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -70,20 +70,20 @@ cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) { char* s; s = syncUtilprintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen); cJSON_AddStringToObject(pRoot, "pCont", s); - free(s); + taosMemoryFree(s); s = syncUtilprintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen); cJSON_AddStringToObject(pRoot, "pCont2", s); - free(s); + taosMemoryFree(s); } else { pRoot = cJSON_CreateObject(); char* s; s = syncUtilprintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen); cJSON_AddStringToObject(pRoot, "pCont", s); - free(s); + taosMemoryFree(s); s = syncUtilprintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen); cJSON_AddStringToObject(pRoot, "pCont2", s); - free(s); + taosMemoryFree(s); } cJSON_AddNumberToObject(pRoot, "msgType", pRpcMsg->msgType); @@ -118,32 +118,32 @@ void syncRpcMsgPrint(SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); printf("syncRpcMsgPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); printf("syncRpcMsgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncRpcMsgLog(SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); sTrace("syncRpcMsgLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); sTrace("syncRpcMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ---- message process SyncTimeout---- SyncTimeout* syncTimeoutBuild() { uint32_t bytes = sizeof(SyncTimeout); - SyncTimeout* pMsg = malloc(bytes); + SyncTimeout* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_TIMEOUT; @@ -161,7 +161,7 @@ SyncTimeout* syncTimeoutBuild2(ESyncTimeoutType timeoutType, uint64_t logicClock void syncTimeoutDestroy(SyncTimeout* pMsg) { if (pMsg != NULL) { - free(pMsg); + taosMemoryFree(pMsg); } } @@ -176,7 +176,7 @@ void syncTimeoutDeserialize(const char* buf, uint32_t len, SyncTimeout* pMsg) { } char* syncTimeoutSerialize2(const SyncTimeout* pMsg, uint32_t* len) { - char* buf = malloc(pMsg->bytes); + char* buf = taosMemoryMalloc(pMsg->bytes); assert(buf != NULL); syncTimeoutSerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { @@ -187,7 +187,7 @@ char* syncTimeoutSerialize2(const SyncTimeout* pMsg, uint32_t* len) { SyncTimeout* syncTimeoutDeserialize2(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SyncTimeout* pMsg = malloc(bytes); + SyncTimeout* pMsg = taosMemoryMalloc(bytes); assert(pMsg != NULL); syncTimeoutDeserialize(buf, len, pMsg); assert(len == pMsg->bytes); @@ -243,32 +243,32 @@ void syncTimeoutPrint(const SyncTimeout* pMsg) { char* serialized = syncTimeout2Str(pMsg); printf("syncTimeoutPrint | len:%zu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncTimeoutPrint2(char* s, const SyncTimeout* pMsg) { char* serialized = syncTimeout2Str(pMsg); printf("syncTimeoutPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncTimeoutLog(const SyncTimeout* pMsg) { char* serialized = syncTimeout2Str(pMsg); sTrace("syncTimeoutLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) { char* serialized = syncTimeout2Str(pMsg); sTrace("syncTimeoutLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ---- message process SyncPing---- SyncPing* syncPingBuild(uint32_t dataLen) { uint32_t bytes = sizeof(SyncPing) + dataLen; - SyncPing* pMsg = malloc(bytes); + SyncPing* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_PING; @@ -292,7 +292,7 @@ SyncPing* syncPingBuild3(const SRaftId* srcId, const SRaftId* destId) { void syncPingDestroy(SyncPing* pMsg) { if (pMsg != NULL) { - free(pMsg); + taosMemoryFree(pMsg); } } @@ -308,7 +308,7 @@ void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pMsg) { } char* syncPingSerialize2(const SyncPing* pMsg, uint32_t* len) { - char* buf = malloc(pMsg->bytes); + char* buf = taosMemoryMalloc(pMsg->bytes); assert(buf != NULL); syncPingSerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { @@ -319,7 +319,7 @@ char* syncPingSerialize2(const SyncPing* pMsg, uint32_t* len) { SyncPing* syncPingDeserialize2(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SyncPing* pMsg = malloc(bytes); + SyncPing* pMsg = taosMemoryMalloc(bytes); assert(pMsg != NULL); syncPingDeserialize(buf, len, pMsg); assert(len == pMsg->bytes); @@ -385,10 +385,10 @@ cJSON* syncPing2Json(const SyncPing* pMsg) { char* s; s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); - free(s); + taosMemoryFree(s); s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); - free(s); + taosMemoryFree(s); } cJSON* pJson = cJSON_CreateObject(); @@ -408,32 +408,32 @@ void syncPingPrint(const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); printf("syncPingPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncPingPrint2(char* s, const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); printf("syncPingPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncPingLog(const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); sTrace("syncPingLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncPingLog2(char* s, const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); sTrace("syncPingLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ---- message process SyncPingReply---- SyncPingReply* syncPingReplyBuild(uint32_t dataLen) { uint32_t bytes = sizeof(SyncPingReply) + dataLen; - SyncPingReply* pMsg = malloc(bytes); + SyncPingReply* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_PING_REPLY; @@ -457,7 +457,7 @@ SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId) void syncPingReplyDestroy(SyncPingReply* pMsg) { if (pMsg != NULL) { - free(pMsg); + taosMemoryFree(pMsg); } } @@ -473,7 +473,7 @@ void syncPingReplyDeserialize(const char* buf, uint32_t len, SyncPingReply* pMsg } char* syncPingReplySerialize2(const SyncPingReply* pMsg, uint32_t* len) { - char* buf = malloc(pMsg->bytes); + char* buf = taosMemoryMalloc(pMsg->bytes); assert(buf != NULL); syncPingReplySerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { @@ -484,7 +484,7 @@ char* syncPingReplySerialize2(const SyncPingReply* pMsg, uint32_t* len) { SyncPingReply* syncPingReplyDeserialize2(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SyncPingReply* pMsg = malloc(bytes); + SyncPingReply* pMsg = taosMemoryMalloc(bytes); assert(pMsg != NULL); syncPingReplyDeserialize(buf, len, pMsg); assert(len == pMsg->bytes); @@ -550,10 +550,10 @@ cJSON* syncPingReply2Json(const SyncPingReply* pMsg) { char* s; s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); - free(s); + taosMemoryFree(s); s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); - free(s); + taosMemoryFree(s); } cJSON* pJson = cJSON_CreateObject(); @@ -573,32 +573,32 @@ void syncPingReplyPrint(const SyncPingReply* pMsg) { char* serialized = syncPingReply2Str(pMsg); printf("syncPingReplyPrint | len:%zu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncPingReplyPrint2(char* s, const SyncPingReply* pMsg) { char* serialized = syncPingReply2Str(pMsg); printf("syncPingReplyPrint2 | len:%zu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncPingReplyLog(const SyncPingReply* pMsg) { char* serialized = syncPingReply2Str(pMsg); sTrace("syncPingReplyLog | len:%zu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncPingReplyLog2(char* s, const SyncPingReply* pMsg) { char* serialized = syncPingReply2Str(pMsg); sTrace("syncPingReplyLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ---- message process SyncClientRequest---- SyncClientRequest* syncClientRequestBuild(uint32_t dataLen) { uint32_t bytes = sizeof(SyncClientRequest) + dataLen; - SyncClientRequest* pMsg = malloc(bytes); + SyncClientRequest* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_CLIENT_REQUEST; @@ -620,7 +620,7 @@ SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint6 void syncClientRequestDestroy(SyncClientRequest* pMsg) { if (pMsg != NULL) { - free(pMsg); + taosMemoryFree(pMsg); } } @@ -635,7 +635,7 @@ void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientReque } char* syncClientRequestSerialize2(const SyncClientRequest* pMsg, uint32_t* len) { - char* buf = malloc(pMsg->bytes); + char* buf = taosMemoryMalloc(pMsg->bytes); assert(buf != NULL); syncClientRequestSerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { @@ -646,7 +646,7 @@ char* syncClientRequestSerialize2(const SyncClientRequest* pMsg, uint32_t* len) SyncClientRequest* syncClientRequestDeserialize2(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SyncClientRequest* pMsg = malloc(bytes); + SyncClientRequest* pMsg = taosMemoryMalloc(bytes); assert(pMsg != NULL); syncClientRequestDeserialize(buf, len, pMsg); assert(len == pMsg->bytes); @@ -688,10 +688,10 @@ cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) { char* s; s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); - free(s); + taosMemoryFree(s); s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); - free(s); + taosMemoryFree(s); } cJSON* pJson = cJSON_CreateObject(); @@ -711,32 +711,32 @@ void syncClientRequestPrint(const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); printf("syncClientRequestPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); printf("syncClientRequestPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncClientRequestLog(const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); sTrace("syncClientRequestLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); sTrace("syncClientRequestLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ---- message process SyncRequestVote---- SyncRequestVote* syncRequestVoteBuild() { uint32_t bytes = sizeof(SyncRequestVote); - SyncRequestVote* pMsg = malloc(bytes); + SyncRequestVote* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_REQUEST_VOTE; @@ -745,7 +745,7 @@ SyncRequestVote* syncRequestVoteBuild() { void syncRequestVoteDestroy(SyncRequestVote* pMsg) { if (pMsg != NULL) { - free(pMsg); + taosMemoryFree(pMsg); } } @@ -760,7 +760,7 @@ void syncRequestVoteDeserialize(const char* buf, uint32_t len, SyncRequestVote* } char* syncRequestVoteSerialize2(const SyncRequestVote* pMsg, uint32_t* len) { - char* buf = malloc(pMsg->bytes); + char* buf = taosMemoryMalloc(pMsg->bytes); assert(buf != NULL); syncRequestVoteSerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { @@ -771,7 +771,7 @@ char* syncRequestVoteSerialize2(const SyncRequestVote* pMsg, uint32_t* len) { SyncRequestVote* syncRequestVoteDeserialize2(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SyncRequestVote* pMsg = malloc(bytes); + SyncRequestVote* pMsg = taosMemoryMalloc(bytes); assert(pMsg != NULL); syncRequestVoteDeserialize(buf, len, pMsg); assert(len == pMsg->bytes); @@ -857,32 +857,32 @@ void syncRequestVotePrint(const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); printf("syncRequestVotePrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncRequestVotePrint2(char* s, const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); printf("syncRequestVotePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncRequestVoteLog(const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); sTrace("syncRequestVoteLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); sTrace("syncRequestVoteLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ---- message process SyncRequestVoteReply---- SyncRequestVoteReply* syncRequestVoteReplyBuild() { uint32_t bytes = sizeof(SyncRequestVoteReply); - SyncRequestVoteReply* pMsg = malloc(bytes); + SyncRequestVoteReply* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_REQUEST_VOTE_REPLY; @@ -891,7 +891,7 @@ SyncRequestVoteReply* syncRequestVoteReplyBuild() { void syncRequestVoteReplyDestroy(SyncRequestVoteReply* pMsg) { if (pMsg != NULL) { - free(pMsg); + taosMemoryFree(pMsg); } } @@ -906,7 +906,7 @@ void syncRequestVoteReplyDeserialize(const char* buf, uint32_t len, SyncRequestV } char* syncRequestVoteReplySerialize2(const SyncRequestVoteReply* pMsg, uint32_t* len) { - char* buf = malloc(pMsg->bytes); + char* buf = taosMemoryMalloc(pMsg->bytes); assert(buf != NULL); syncRequestVoteReplySerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { @@ -917,7 +917,7 @@ char* syncRequestVoteReplySerialize2(const SyncRequestVoteReply* pMsg, uint32_t* SyncRequestVoteReply* syncRequestVoteReplyDeserialize2(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SyncRequestVoteReply* pMsg = malloc(bytes); + SyncRequestVoteReply* pMsg = taosMemoryMalloc(bytes); assert(pMsg != NULL); syncRequestVoteReplyDeserialize(buf, len, pMsg); assert(len == pMsg->bytes); @@ -1000,32 +1000,32 @@ void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); printf("syncRequestVoteReplyPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); printf("syncRequestVoteReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); sTrace("syncRequestVoteReplyLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); sTrace("syncRequestVoteReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ---- message process SyncAppendEntries---- SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen) { uint32_t bytes = sizeof(SyncAppendEntries) + dataLen; - SyncAppendEntries* pMsg = malloc(bytes); + SyncAppendEntries* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_APPEND_ENTRIES; @@ -1035,7 +1035,7 @@ SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen) { void syncAppendEntriesDestroy(SyncAppendEntries* pMsg) { if (pMsg != NULL) { - free(pMsg); + taosMemoryFree(pMsg); } } @@ -1051,7 +1051,7 @@ void syncAppendEntriesDeserialize(const char* buf, uint32_t len, SyncAppendEntri } char* syncAppendEntriesSerialize2(const SyncAppendEntries* pMsg, uint32_t* len) { - char* buf = malloc(pMsg->bytes); + char* buf = taosMemoryMalloc(pMsg->bytes); assert(buf != NULL); syncAppendEntriesSerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { @@ -1062,7 +1062,7 @@ char* syncAppendEntriesSerialize2(const SyncAppendEntries* pMsg, uint32_t* len) SyncAppendEntries* syncAppendEntriesDeserialize2(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SyncAppendEntries* pMsg = malloc(bytes); + SyncAppendEntries* pMsg = taosMemoryMalloc(bytes); assert(pMsg != NULL); syncAppendEntriesDeserialize(buf, len, pMsg); assert(len == pMsg->bytes); @@ -1140,10 +1140,10 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) { char* s; s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); - free(s); + taosMemoryFree(s); s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); - free(s); + taosMemoryFree(s); } cJSON* pJson = cJSON_CreateObject(); @@ -1163,32 +1163,32 @@ void syncAppendEntriesPrint(const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); printf("syncAppendEntriesPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); printf("syncAppendEntriesPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncAppendEntriesLog(const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); sTrace("syncAppendEntriesLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); sTrace("syncAppendEntriesLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // ---- message process SyncAppendEntriesReply---- SyncAppendEntriesReply* syncAppendEntriesReplyBuild() { uint32_t bytes = sizeof(SyncAppendEntriesReply); - SyncAppendEntriesReply* pMsg = malloc(bytes); + SyncAppendEntriesReply* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_APPEND_ENTRIES_REPLY; @@ -1197,7 +1197,7 @@ SyncAppendEntriesReply* syncAppendEntriesReplyBuild() { void syncAppendEntriesReplyDestroy(SyncAppendEntriesReply* pMsg) { if (pMsg != NULL) { - free(pMsg); + taosMemoryFree(pMsg); } } @@ -1212,7 +1212,7 @@ void syncAppendEntriesReplyDeserialize(const char* buf, uint32_t len, SyncAppend } char* syncAppendEntriesReplySerialize2(const SyncAppendEntriesReply* pMsg, uint32_t* len) { - char* buf = malloc(pMsg->bytes); + char* buf = taosMemoryMalloc(pMsg->bytes); assert(buf != NULL); syncAppendEntriesReplySerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { @@ -1223,7 +1223,7 @@ char* syncAppendEntriesReplySerialize2(const SyncAppendEntriesReply* pMsg, uint3 SyncAppendEntriesReply* syncAppendEntriesReplyDeserialize2(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SyncAppendEntriesReply* pMsg = malloc(bytes); + SyncAppendEntriesReply* pMsg = taosMemoryMalloc(bytes); assert(pMsg != NULL); syncAppendEntriesReplyDeserialize(buf, len, pMsg); assert(len == pMsg->bytes); @@ -1309,24 +1309,24 @@ void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); printf("syncAppendEntriesReplyPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); printf("syncAppendEntriesReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); sTrace("syncAppendEntriesReplyLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); sTrace("syncAppendEntriesReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index 9b9842b81d..3de39a6aa8 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -18,7 +18,7 @@ SSyncRaftEntry* syncEntryBuild(uint32_t dataLen) { uint32_t bytes = sizeof(SSyncRaftEntry) + dataLen; - SSyncRaftEntry* pEntry = malloc(bytes); + SSyncRaftEntry* pEntry = taosMemoryMalloc(bytes); assert(pEntry != NULL); memset(pEntry, 0, bytes); pEntry->bytes = bytes; @@ -63,13 +63,13 @@ SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index) { void syncEntryDestory(SSyncRaftEntry* pEntry) { if (pEntry != NULL) { - free(pEntry); + taosMemoryFree(pEntry); } } // step 5. SSyncRaftEntry => bin, to raft log char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len) { - char* buf = malloc(pEntry->bytes); + char* buf = taosMemoryMalloc(pEntry->bytes); assert(buf != NULL); memcpy(buf, pEntry, pEntry->bytes); if (len != NULL) { @@ -81,7 +81,7 @@ char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len) { // step 6. bin => SSyncRaftEntry, from raft log SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len) { uint32_t bytes = *((uint32_t*)buf); - SSyncRaftEntry* pEntry = malloc(bytes); + SSyncRaftEntry* pEntry = taosMemoryMalloc(bytes); assert(pEntry != NULL); memcpy(pEntry, buf, len); assert(len == pEntry->bytes); @@ -109,11 +109,11 @@ cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { char* s; s = syncUtilprintBin((char*)(pEntry->data), pEntry->dataLen); cJSON_AddStringToObject(pRoot, "data", s); - free(s); + taosMemoryFree(s); s = syncUtilprintBin2((char*)(pEntry->data), pEntry->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); - free(s); + taosMemoryFree(s); } cJSON* pJson = cJSON_CreateObject(); @@ -142,24 +142,24 @@ void syncEntryPrint(const SSyncRaftEntry* pObj) { char* serialized = syncEntry2Str(pObj); printf("syncEntryPrint | len:%zu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) { char* serialized = syncEntry2Str(pObj); printf("syncEntryPrint2 | len:%zu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void syncEntryLog(const SSyncRaftEntry* pObj) { char* serialized = syncEntry2Str(pObj); sTrace("syncEntryLog | len:%zu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) { char* serialized = syncEntry2Str(pObj); sTrace("syncEntryLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index b28f899aa9..63c6265d10 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -17,10 +17,10 @@ #include "wal.h" SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { - SSyncLogStore* pLogStore = malloc(sizeof(SSyncLogStore)); + SSyncLogStore* pLogStore = taosMemoryMalloc(sizeof(SSyncLogStore)); assert(pLogStore != NULL); - pLogStore->data = malloc(sizeof(SSyncLogStoreData)); + pLogStore->data = taosMemoryMalloc(sizeof(SSyncLogStoreData)); assert(pLogStore->data != NULL); SSyncLogStoreData* pData = pLogStore->data; @@ -39,8 +39,8 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { void logStoreDestory(SSyncLogStore* pLogStore) { if (pLogStore != NULL) { - free(pLogStore->data); - free(pLogStore); + taosMemoryFree(pLogStore->data); + taosMemoryFree(pLogStore); } } @@ -62,7 +62,7 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { assert(walWrite(pWal, pEntry->index, pEntry->entryType, serialized, len) == 0); walFsync(pWal, true); - free(serialized); + taosMemoryFree(serialized); return code; } @@ -103,7 +103,7 @@ SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) { SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore); if (pLastEntry != NULL) { lastTerm = pLastEntry->term; - free(pLastEntry); + taosMemoryFree(pLastEntry); } return lastTerm; } @@ -202,26 +202,26 @@ void logStorePrint(SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); printf("logStorePrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void logStorePrint2(char* s, SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); printf("logStorePrint | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void logStoreLog(SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); sTrace("logStorePrint | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void logStoreLog2(char* s, SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); sTrace("logStorePrint | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // for debug ----------------- @@ -229,24 +229,24 @@ void logStoreSimplePrint(SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); printf("logStoreSimplePrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); printf("logStoreSimplePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void logStoreSimpleLog(SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); sTrace("logStoreSimpleLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); sTrace("logStoreSimpleLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index 3f6db129ce..c9054d088e 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -26,7 +26,7 @@ static bool raftStoreFileExist(char *path); SRaftStore *raftStoreOpen(const char *path) { int32_t ret; - SRaftStore *pRaftStore = malloc(sizeof(SRaftStore)); + SRaftStore *pRaftStore = taosMemoryMalloc(sizeof(SRaftStore)); if (pRaftStore == NULL) { sError("raftStoreOpen malloc error"); return NULL; @@ -75,7 +75,7 @@ int32_t raftStoreClose(SRaftStore *pRaftStore) { assert(pRaftStore != NULL); taosCloseFile(&pRaftStore->pFile); - free(pRaftStore); + taosMemoryFree(pRaftStore); pRaftStore = NULL; return 0; } @@ -128,7 +128,7 @@ int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) { assert(len2 < len); memset(buf, 0, len); snprintf(buf, len, "%s", serialized); - free(serialized); + taosMemoryFree(serialized); cJSON_Delete(pRoot); return 0; @@ -226,23 +226,23 @@ void raftStorePrint(SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); printf("raftStorePrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void raftStorePrint2(char *s, SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); printf("raftStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void raftStoreLog(SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); sTrace("raftStoreLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void raftStoreLog2(char *s, SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); sTrace("raftStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 943b268cd3..3ced7a18bc 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -86,7 +86,7 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) { assert(len == pEntry->bytes); memcpy(pMsg->data, serialized, len); - free(serialized); + taosMemoryFree(serialized); syncEntryDestory(pEntry); } else { diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 8fc17ccb51..287500a587 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -76,10 +76,10 @@ bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId = // ---- SSyncBuffer ----- void syncUtilbufBuild(SSyncBuffer* syncBuf, size_t len) { syncBuf->len = len; - syncBuf->data = malloc(syncBuf->len); + syncBuf->data = taosMemoryMalloc(syncBuf->len); } -void syncUtilbufDestroy(SSyncBuffer* syncBuf) { free(syncBuf->data); } +void syncUtilbufDestroy(SSyncBuffer* syncBuf) { taosMemoryFree(syncBuf->data); } void syncUtilbufCopy(const SSyncBuffer* src, SSyncBuffer* dest) { dest->len = src->len; @@ -88,7 +88,7 @@ void syncUtilbufCopy(const SSyncBuffer* src, SSyncBuffer* dest) { void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest) { dest->len = src->len; - dest->data = malloc(dest->len); + dest->data = taosMemoryMalloc(dest->len); memcpy(dest->data, src->data, dest->len); } @@ -161,7 +161,7 @@ bool syncUtilCanPrint(char c) { } char* syncUtilprintBin(char* ptr, uint32_t len) { - char* s = malloc(len + 1); + char* s = taosMemoryMalloc(len + 1); assert(s != NULL); memset(s, 0, len + 1); memcpy(s, ptr, len); @@ -176,7 +176,7 @@ char* syncUtilprintBin(char* ptr, uint32_t len) { char* syncUtilprintBin2(char* ptr, uint32_t len) { uint32_t len2 = len * 4 + 1; - char* s = malloc(len2); + char* s = taosMemoryMalloc(len2); assert(s != NULL); memset(s, 0, len2); diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index 69a4c48f39..733dfd05b6 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -23,7 +23,7 @@ static void voteGrantedClearVotes(SVotesGranted *pVotesGranted) { } SVotesGranted *voteGrantedCreate(SSyncNode *pSyncNode) { - SVotesGranted *pVotesGranted = malloc(sizeof(SVotesGranted)); + SVotesGranted *pVotesGranted = taosMemoryMalloc(sizeof(SVotesGranted)); assert(pVotesGranted != NULL); memset(pVotesGranted, 0, sizeof(SVotesGranted)); @@ -41,7 +41,7 @@ SVotesGranted *voteGrantedCreate(SSyncNode *pSyncNode) { void voteGrantedDestroy(SVotesGranted *pVotesGranted) { if (pVotesGranted != NULL) { - free(pVotesGranted); + taosMemoryFree(pVotesGranted); } } @@ -89,12 +89,12 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) { for (int i = 0; i < pVotesGranted->replicaNum; ++i) { cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesGranted->replicas))[i])); } - int *arr = (int *)malloc(sizeof(int) * pVotesGranted->replicaNum); + int *arr = (int *)taosMemoryMalloc(sizeof(int) * pVotesGranted->replicaNum); for (int i = 0; i < pVotesGranted->replicaNum; ++i) { arr[i] = pVotesGranted->isGranted[i]; } cJSON *pIsGranted = cJSON_CreateIntArray(arr, pVotesGranted->replicaNum); - free(arr); + taosMemoryFree(arr); cJSON_AddItemToObject(pRoot, "isGranted", pIsGranted); cJSON_AddNumberToObject(pRoot, "votes", pVotesGranted->votes); @@ -126,31 +126,31 @@ void voteGrantedPrint(SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); printf("voteGrantedPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void voteGrantedPrint2(char *s, SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); printf("voteGrantedPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void voteGrantedLog(SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); sTrace("voteGrantedLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void voteGrantedLog2(char *s, SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); sTrace("voteGrantedLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } // SVotesRespond ----------------------------- SVotesRespond *votesRespondCreate(SSyncNode *pSyncNode) { - SVotesRespond *pVotesRespond = malloc(sizeof(SVotesRespond)); + SVotesRespond *pVotesRespond = taosMemoryMalloc(sizeof(SVotesRespond)); assert(pVotesRespond != NULL); memset(pVotesRespond, 0, sizeof(SVotesRespond)); @@ -164,7 +164,7 @@ SVotesRespond *votesRespondCreate(SSyncNode *pSyncNode) { void votesRespondDestory(SVotesRespond *pVotesRespond) { if (pVotesRespond != NULL) { - free(pVotesRespond); + taosMemoryFree(pVotesRespond); } } @@ -213,7 +213,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) { cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesRespond->replicas))[i])); } int respondNum = 0; - int *arr = (int *)malloc(sizeof(int) * pVotesRespond->replicaNum); + int *arr = (int *)taosMemoryMalloc(sizeof(int) * pVotesRespond->replicaNum); for (int i = 0; i < pVotesRespond->replicaNum; ++i) { arr[i] = pVotesRespond->isRespond[i]; if (pVotesRespond->isRespond[i]) { @@ -221,7 +221,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) { } } cJSON *pIsRespond = cJSON_CreateIntArray(arr, pVotesRespond->replicaNum); - free(arr); + taosMemoryFree(arr); cJSON_AddItemToObject(pRoot, "isRespond", pIsRespond); cJSON_AddNumberToObject(pRoot, "respondNum", respondNum); @@ -248,24 +248,24 @@ void votesRespondPrint(SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); printf("votesRespondPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void votesRespondPrint2(char *s, SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); printf("votesRespondPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); - free(serialized); + taosMemoryFree(serialized); } void votesRespondLog(SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); sTrace("votesRespondLog | len:%lu | %s", strlen(serialized), serialized); - free(serialized); + taosMemoryFree(serialized); } void votesRespondLog2(char *s, SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); sTrace("votesRespondLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - free(serialized); + taosMemoryFree(serialized); } diff --git a/source/libs/sync/test/syncAppendEntriesReplyTest.cpp b/source/libs/sync/test/syncAppendEntriesReplyTest.cpp index 362da67c66..72aeb155e7 100644 --- a/source/libs/sync/test/syncAppendEntriesReplyTest.cpp +++ b/source/libs/sync/test/syncAppendEntriesReplyTest.cpp @@ -34,14 +34,14 @@ void test1() { void test2() { SyncAppendEntriesReply *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)malloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncAppendEntriesReplySerialize(pMsg, serialized, len); SyncAppendEntriesReply *pMsg2 = syncAppendEntriesReplyBuild(); syncAppendEntriesReplyDeserialize(serialized, len, pMsg2); syncAppendEntriesReplyPrint2((char *)"test2: syncAppendEntriesReplySerialize -> syncAppendEntriesReplyDeserialize ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncAppendEntriesReplyDestroy(pMsg); syncAppendEntriesReplyDestroy(pMsg2); } @@ -54,7 +54,7 @@ void test3() { syncAppendEntriesReplyPrint2((char *)"test3: syncAppendEntriesReplySerialize3 -> syncAppendEntriesReplyDeserialize2 ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncAppendEntriesReplyDestroy(pMsg); syncAppendEntriesReplyDestroy(pMsg2); } diff --git a/source/libs/sync/test/syncAppendEntriesTest.cpp b/source/libs/sync/test/syncAppendEntriesTest.cpp index 687d9bcb94..69a0aee9a8 100644 --- a/source/libs/sync/test/syncAppendEntriesTest.cpp +++ b/source/libs/sync/test/syncAppendEntriesTest.cpp @@ -36,13 +36,13 @@ void test1() { void test2() { SyncAppendEntries *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)malloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncAppendEntriesSerialize(pMsg, serialized, len); SyncAppendEntries *pMsg2 = syncAppendEntriesBuild(pMsg->dataLen); syncAppendEntriesDeserialize(serialized, len, pMsg2); syncAppendEntriesPrint2((char *)"test2: syncAppendEntriesSerialize -> syncAppendEntriesDeserialize ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncAppendEntriesDestroy(pMsg); syncAppendEntriesDestroy(pMsg2); } @@ -54,7 +54,7 @@ void test3() { SyncAppendEntries *pMsg2 = syncAppendEntriesDeserialize2(serialized, len); syncAppendEntriesPrint2((char *)"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncAppendEntriesDestroy(pMsg); syncAppendEntriesDestroy(pMsg2); } @@ -63,7 +63,7 @@ void test4() { SyncAppendEntries *pMsg = createMsg(); SRpcMsg rpcMsg; syncAppendEntries2RpcMsg(pMsg, &rpcMsg); - SyncAppendEntries *pMsg2 = (SyncAppendEntries *)malloc(rpcMsg.contLen); + SyncAppendEntries *pMsg2 = (SyncAppendEntries *)taosMemoryMalloc(rpcMsg.contLen); syncAppendEntriesFromRpcMsg(&rpcMsg, pMsg2); syncAppendEntriesPrint2((char *)"test4: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg ", pMsg2); diff --git a/source/libs/sync/test/syncClientRequestTest.cpp b/source/libs/sync/test/syncClientRequestTest.cpp index 6323f53a03..f22478d538 100644 --- a/source/libs/sync/test/syncClientRequestTest.cpp +++ b/source/libs/sync/test/syncClientRequestTest.cpp @@ -34,13 +34,13 @@ void test1() { void test2() { SyncClientRequest *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)malloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncClientRequestSerialize(pMsg, serialized, len); SyncClientRequest *pMsg2 = syncClientRequestBuild(pMsg->dataLen); syncClientRequestDeserialize(serialized, len, pMsg2); syncClientRequestPrint2((char *)"test2: syncClientRequestSerialize -> syncClientRequestDeserialize ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncClientRequestDestroy(pMsg); syncClientRequestDestroy(pMsg2); } @@ -52,7 +52,7 @@ void test3() { SyncClientRequest *pMsg2 = syncClientRequestDeserialize2(serialized, len); syncClientRequestPrint2((char *)"test3: syncClientRequestSerialize3 -> syncClientRequestDeserialize2 ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncClientRequestDestroy(pMsg); syncClientRequestDestroy(pMsg2); } @@ -61,7 +61,7 @@ void test4() { SyncClientRequest *pMsg = createMsg(); SRpcMsg rpcMsg; syncClientRequest2RpcMsg(pMsg, &rpcMsg); - SyncClientRequest *pMsg2 = (SyncClientRequest *)malloc(rpcMsg.contLen); + SyncClientRequest *pMsg2 = (SyncClientRequest *)taosMemoryMalloc(rpcMsg.contLen); syncClientRequestFromRpcMsg(&rpcMsg, pMsg2); syncClientRequestPrint2((char *)"test4: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg ", pMsg2); diff --git a/source/libs/sync/test/syncElectTest.cpp b/source/libs/sync/test/syncElectTest.cpp index 99cfe75867..251a4b538f 100644 --- a/source/libs/sync/test/syncElectTest.cpp +++ b/source/libs/sync/test/syncElectTest.cpp @@ -88,7 +88,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncElectTest2.cpp b/source/libs/sync/test/syncElectTest2.cpp index 8463ffd448..709d9d8580 100644 --- a/source/libs/sync/test/syncElectTest2.cpp +++ b/source/libs/sync/test/syncElectTest2.cpp @@ -91,7 +91,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncElectTest3.cpp b/source/libs/sync/test/syncElectTest3.cpp index 45c5488c60..e36a2d0fb1 100644 --- a/source/libs/sync/test/syncElectTest3.cpp +++ b/source/libs/sync/test/syncElectTest3.cpp @@ -94,7 +94,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncEncodeTest.cpp b/source/libs/sync/test/syncEncodeTest.cpp index e554858072..b1ba95dc3e 100644 --- a/source/libs/sync/test/syncEncodeTest.cpp +++ b/source/libs/sync/test/syncEncodeTest.cpp @@ -87,16 +87,16 @@ void initRaftId(SSyncNode *pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char *s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } SRpcMsg *step0() { - SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + SRpcMsg *pMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); memset(pMsg, 0, sizeof(SRpcMsg)); pMsg->msgType = 9999; pMsg->contLen = 32; - pMsg->pCont = malloc(pMsg->contLen); + pMsg->pCont = taosMemoryMalloc(pMsg->contLen); snprintf((char *)(pMsg->pCont), pMsg->contLen, "hello, world"); return pMsg; } @@ -107,7 +107,7 @@ SyncClientRequest *step1(const SRpcMsg *pMsg) { } SRpcMsg *step2(const SyncClientRequest *pMsg) { - SRpcMsg *pRetMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + SRpcMsg *pRetMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); syncClientRequest2RpcMsg(pMsg, pRetMsg); return pRetMsg; } @@ -133,7 +133,7 @@ SSyncRaftEntry *step6(const char *pMsg, uint32_t len) { } SRpcMsg *step7(const SSyncRaftEntry *pMsg) { - SRpcMsg *pRetMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + SRpcMsg *pRetMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); syncEntry2OriginalRpc(pMsg, pRetMsg); return pRetMsg; } @@ -190,7 +190,7 @@ int main(int argc, char **argv) { char * pMsg5 = step5(pMsg4, &len); char * s = syncUtilprintBin(pMsg5, len); printf("==step5== [%s] \n", s); - free(s); + taosMemoryFree(s); // step6 SSyncRaftEntry *pMsg6 = step6(pMsg5, len); diff --git a/source/libs/sync/test/syncEnqTest.cpp b/source/libs/sync/test/syncEnqTest.cpp index 57315f40ec..48cc7caf2f 100644 --- a/source/libs/sync/test/syncEnqTest.cpp +++ b/source/libs/sync/test/syncEnqTest.cpp @@ -66,7 +66,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncEntryTest.cpp b/source/libs/sync/test/syncEntryTest.cpp index 2c8433426a..e8427e8168 100644 --- a/source/libs/sync/test/syncEntryTest.cpp +++ b/source/libs/sync/test/syncEntryTest.cpp @@ -78,7 +78,7 @@ void test4() { SSyncRaftEntry* pEntry2 = syncEntryDeserialize(serialized, len); syncEntryPrint(pEntry2); - free(serialized); + taosMemoryFree(serialized); syncEntryDestory(pEntry2); syncEntryDestory(pEntry); } diff --git a/source/libs/sync/test/syncIOSendMsgTest.cpp b/source/libs/sync/test/syncIOSendMsgTest.cpp index 0fc3ebfe4c..913e57e59a 100644 --- a/source/libs/sync/test/syncIOSendMsgTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgTest.cpp @@ -66,7 +66,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncIndexMgrTest.cpp b/source/libs/sync/test/syncIndexMgrTest.cpp index 6bad8f09cf..319ea3e15a 100644 --- a/source/libs/sync/test/syncIndexMgrTest.cpp +++ b/source/libs/sync/test/syncIndexMgrTest.cpp @@ -68,7 +68,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } @@ -93,7 +93,7 @@ int main(int argc, char** argv) { char* serialized = syncNode2Str(pSyncNode); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); initRaftId(pSyncNode); @@ -105,7 +105,7 @@ int main(int argc, char** argv) { char* serialized = syncIndexMgr2Str(pSyncIndexMgr); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } syncIndexMgrSetIndex(pSyncIndexMgr, &ids[0], 100); @@ -117,7 +117,7 @@ int main(int argc, char** argv) { char* serialized = syncIndexMgr2Str(pSyncIndexMgr); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } printf("---------------------------------------\n"); @@ -132,7 +132,7 @@ int main(int argc, char** argv) { char* serialized = syncIndexMgr2Str(pSyncIndexMgr); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } syncIndexMgrDestroy(pSyncIndexMgr); diff --git a/source/libs/sync/test/syncInitTest.cpp b/source/libs/sync/test/syncInitTest.cpp index a3e5f41c85..48b5488e41 100644 --- a/source/libs/sync/test/syncInitTest.cpp +++ b/source/libs/sync/test/syncInitTest.cpp @@ -65,7 +65,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncLogStoreTest.cpp b/source/libs/sync/test/syncLogStoreTest.cpp index c1cb66f382..a5adba9a88 100644 --- a/source/libs/sync/test/syncLogStoreTest.cpp +++ b/source/libs/sync/test/syncLogStoreTest.cpp @@ -116,7 +116,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncPingReplyTest.cpp b/source/libs/sync/test/syncPingReplyTest.cpp index 8e1448e781..40592eab6f 100644 --- a/source/libs/sync/test/syncPingReplyTest.cpp +++ b/source/libs/sync/test/syncPingReplyTest.cpp @@ -33,13 +33,13 @@ void test1() { void test2() { SyncPingReply *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)malloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncPingReplySerialize(pMsg, serialized, len); SyncPingReply *pMsg2 = syncPingReplyBuild(pMsg->dataLen); syncPingReplyDeserialize(serialized, len, pMsg2); syncPingReplyPrint2((char *)"test2: syncPingReplySerialize -> syncPingReplyDeserialize ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncPingReplyDestroy(pMsg); syncPingReplyDestroy(pMsg2); } @@ -51,7 +51,7 @@ void test3() { SyncPingReply *pMsg2 = syncPingReplyDeserialize2(serialized, len); syncPingReplyPrint2((char *)"test3: syncPingReplySerialize3 -> syncPingReplyDeserialize2 ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncPingReplyDestroy(pMsg); syncPingReplyDestroy(pMsg2); } @@ -60,7 +60,7 @@ void test4() { SyncPingReply *pMsg = createMsg(); SRpcMsg rpcMsg; syncPingReply2RpcMsg(pMsg, &rpcMsg); - SyncPingReply *pMsg2 = (SyncPingReply *)malloc(rpcMsg.contLen); + SyncPingReply *pMsg2 = (SyncPingReply *)taosMemoryMalloc(rpcMsg.contLen); syncPingReplyFromRpcMsg(&rpcMsg, pMsg2); syncPingReplyPrint2((char *)"test4: syncPingReply2RpcMsg -> syncPingReplyFromRpcMsg ", pMsg2); diff --git a/source/libs/sync/test/syncPingSelfTest.cpp b/source/libs/sync/test/syncPingSelfTest.cpp index 05e4d99cb0..677518c6ac 100644 --- a/source/libs/sync/test/syncPingSelfTest.cpp +++ b/source/libs/sync/test/syncPingSelfTest.cpp @@ -65,7 +65,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncPingTest.cpp b/source/libs/sync/test/syncPingTest.cpp index 83394b0e77..eb774d77c3 100644 --- a/source/libs/sync/test/syncPingTest.cpp +++ b/source/libs/sync/test/syncPingTest.cpp @@ -33,13 +33,13 @@ void test1() { void test2() { SyncPing *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)malloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncPingSerialize(pMsg, serialized, len); SyncPing *pMsg2 = syncPingBuild(pMsg->dataLen); syncPingDeserialize(serialized, len, pMsg2); syncPingPrint2((char *)"test2: syncPingSerialize -> syncPingDeserialize ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncPingDestroy(pMsg); syncPingDestroy(pMsg2); } @@ -51,7 +51,7 @@ void test3() { SyncPing *pMsg2 = syncPingDeserialize2(serialized, len); syncPingPrint2((char *)"test3: syncPingSerialize3 -> syncPingDeserialize2 ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncPingDestroy(pMsg); syncPingDestroy(pMsg2); } @@ -60,7 +60,7 @@ void test4() { SyncPing *pMsg = createMsg(); SRpcMsg rpcMsg; syncPing2RpcMsg(pMsg, &rpcMsg); - SyncPing *pMsg2 = (SyncPing *)malloc(rpcMsg.contLen); + SyncPing *pMsg2 = (SyncPing *)taosMemoryMalloc(rpcMsg.contLen); syncPingFromRpcMsg(&rpcMsg, pMsg2); syncPingPrint2((char *)"test4: syncPing2RpcMsg -> syncPingFromRpcMsg ", pMsg2); diff --git a/source/libs/sync/test/syncPingTimerTest.cpp b/source/libs/sync/test/syncPingTimerTest.cpp index 20d4a9ce58..3c5e76ca14 100644 --- a/source/libs/sync/test/syncPingTimerTest.cpp +++ b/source/libs/sync/test/syncPingTimerTest.cpp @@ -65,7 +65,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncPingTimerTest2.cpp b/source/libs/sync/test/syncPingTimerTest2.cpp index 2a041f3f5d..554f67d365 100644 --- a/source/libs/sync/test/syncPingTimerTest2.cpp +++ b/source/libs/sync/test/syncPingTimerTest2.cpp @@ -65,7 +65,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncRaftStoreTest.cpp b/source/libs/sync/test/syncRaftStoreTest.cpp index 688802625a..460ff90f4f 100644 --- a/source/libs/sync/test/syncRaftStoreTest.cpp +++ b/source/libs/sync/test/syncRaftStoreTest.cpp @@ -25,7 +25,7 @@ void initRaftId() { ids[i].vgId = 1234; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } diff --git a/source/libs/sync/test/syncRefTest.cpp b/source/libs/sync/test/syncRefTest.cpp index 8e9adbbc15..96062b1a91 100644 --- a/source/libs/sync/test/syncRefTest.cpp +++ b/source/libs/sync/test/syncRefTest.cpp @@ -33,7 +33,7 @@ typedef struct SyncObj { static void syncFreeObj(void *param) { SyncObj *pObj = (SyncObj *)param; printf("syncFreeObj name:%s rid:%ld \n", pObj->name, pObj->rid); - free(pObj); + taosMemoryFree(pObj); } int32_t init() { @@ -54,7 +54,7 @@ void cleanup() { } int64_t start() { - SyncObj *pObj = (SyncObj *)malloc(sizeof(SyncObj)); + SyncObj *pObj = (SyncObj *)taosMemoryMalloc(sizeof(SyncObj)); assert(pObj != NULL); pObj->data = &g; diff --git a/source/libs/sync/test/syncReplicateLoadTest.cpp b/source/libs/sync/test/syncReplicateLoadTest.cpp index b2d3f1a98d..0841083b4a 100644 --- a/source/libs/sync/test/syncReplicateLoadTest.cpp +++ b/source/libs/sync/test/syncReplicateLoadTest.cpp @@ -53,7 +53,7 @@ void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, boo } void initFsm() { - pFsm = (SSyncFSM *)malloc(sizeof(SSyncFSM)); + pFsm = (SSyncFSM *)taosMemoryMalloc(sizeof(SSyncFSM)); pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; @@ -126,16 +126,16 @@ void initRaftId(SSyncNode *pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char *s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } SRpcMsg *step0(int i) { - SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + SRpcMsg *pMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); memset(pMsg, 0, sizeof(SRpcMsg)); pMsg->msgType = 9999; pMsg->contLen = 128; - pMsg->pCont = malloc(pMsg->contLen); + pMsg->pCont = taosMemoryMalloc(pMsg->contLen); snprintf((char *)(pMsg->pCont), pMsg->contLen, "value-%u-%d", ports[myIndex], i); return pMsg; } diff --git a/source/libs/sync/test/syncReplicateTest.cpp b/source/libs/sync/test/syncReplicateTest.cpp index 09aec6534f..9783bac7e5 100644 --- a/source/libs/sync/test/syncReplicateTest.cpp +++ b/source/libs/sync/test/syncReplicateTest.cpp @@ -54,7 +54,7 @@ void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, boo } void initFsm() { - pFsm = (SSyncFSM *)malloc(sizeof(SSyncFSM)); + pFsm = (SSyncFSM *)taosMemoryMalloc(sizeof(SSyncFSM)); pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; @@ -121,16 +121,16 @@ void initRaftId(SSyncNode *pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char *s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } SRpcMsg *step0(int i) { - SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + SRpcMsg *pMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); memset(pMsg, 0, sizeof(SRpcMsg)); pMsg->msgType = 9999; pMsg->contLen = 128; - pMsg->pCont = malloc(pMsg->contLen); + pMsg->pCont = taosMemoryMalloc(pMsg->contLen); snprintf((char *)(pMsg->pCont), pMsg->contLen, "value-%u-%d", ports[myIndex], i); return pMsg; } diff --git a/source/libs/sync/test/syncReplicateTest2.cpp b/source/libs/sync/test/syncReplicateTest2.cpp index 8739a8d12f..430df7eebd 100644 --- a/source/libs/sync/test/syncReplicateTest2.cpp +++ b/source/libs/sync/test/syncReplicateTest2.cpp @@ -53,7 +53,7 @@ void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, boo } void initFsm() { - pFsm = (SSyncFSM *)malloc(sizeof(SSyncFSM)); + pFsm = (SSyncFSM *)taosMemoryMalloc(sizeof(SSyncFSM)); pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; @@ -126,16 +126,16 @@ void initRaftId(SSyncNode *pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char *s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } SRpcMsg *step0(int i) { - SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + SRpcMsg *pMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); memset(pMsg, 0, sizeof(SRpcMsg)); pMsg->msgType = 9999; pMsg->contLen = 128; - pMsg->pCont = malloc(pMsg->contLen); + pMsg->pCont = taosMemoryMalloc(pMsg->contLen); snprintf((char *)(pMsg->pCont), pMsg->contLen, "value-%u-%d", ports[myIndex], i); return pMsg; } @@ -181,7 +181,7 @@ int main(int argc, char **argv) { syncPropose(rid, pMsg0, true); taosMsleep(1000); - free(pMsg0); + taosMemoryFree(pMsg0); sTrace( "syncPropose sleep, state: %d, %s, term:%lu electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, " diff --git a/source/libs/sync/test/syncReplicateTest3.cpp b/source/libs/sync/test/syncReplicateTest3.cpp index ad2172ccd2..792b9c94cf 100644 --- a/source/libs/sync/test/syncReplicateTest3.cpp +++ b/source/libs/sync/test/syncReplicateTest3.cpp @@ -55,7 +55,7 @@ void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, boo } void initFsm() { - pFsm = (SSyncFSM *)malloc(sizeof(SSyncFSM)); + pFsm = (SSyncFSM *)taosMemoryMalloc(sizeof(SSyncFSM)); pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; @@ -128,16 +128,16 @@ void initRaftId(SSyncNode *pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char *s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } SRpcMsg *step0(int i) { - SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + SRpcMsg *pMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); memset(pMsg, 0, sizeof(SRpcMsg)); pMsg->msgType = 9999; pMsg->contLen = 128; - pMsg->pCont = malloc(pMsg->contLen); + pMsg->pCont = taosMemoryMalloc(pMsg->contLen); snprintf((char *)(pMsg->pCont), pMsg->contLen, "value-%u-%d", ports[myIndex], i); return pMsg; } @@ -193,7 +193,7 @@ int main(int argc, char **argv) { syncPropose(rid, pMsg0, true); taosMsleep(sleepMS); - free(pMsg0); + taosMemoryFree(pMsg0); sTrace( "syncPropose sleep, state: %d, %s, term:%lu electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, " diff --git a/source/libs/sync/test/syncRequestVoteReplyTest.cpp b/source/libs/sync/test/syncRequestVoteReplyTest.cpp index 2bce3e4cd6..9e0ebee313 100644 --- a/source/libs/sync/test/syncRequestVoteReplyTest.cpp +++ b/source/libs/sync/test/syncRequestVoteReplyTest.cpp @@ -34,13 +34,13 @@ void test1() { void test2() { SyncRequestVoteReply *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)malloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncRequestVoteReplySerialize(pMsg, serialized, len); SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyBuild(); syncRequestVoteReplyDeserialize(serialized, len, pMsg2); syncRequestVoteReplyPrint2((char *)"test2: syncRequestVoteReplySerialize -> syncRequestVoteReplyDeserialize ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncRequestVoteReplyDestroy(pMsg); syncRequestVoteReplyDestroy(pMsg2); } @@ -53,7 +53,7 @@ void test3() { syncRequestVoteReplyPrint2((char *)"test3: syncRequestVoteReplySerialize3 -> syncRequestVoteReplyDeserialize2 ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncRequestVoteReplyDestroy(pMsg); syncRequestVoteReplyDestroy(pMsg2); } diff --git a/source/libs/sync/test/syncRequestVoteTest.cpp b/source/libs/sync/test/syncRequestVoteTest.cpp index 22f47046de..6b2120e124 100644 --- a/source/libs/sync/test/syncRequestVoteTest.cpp +++ b/source/libs/sync/test/syncRequestVoteTest.cpp @@ -35,13 +35,13 @@ void test1() { void test2() { SyncRequestVote *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)malloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncRequestVoteSerialize(pMsg, serialized, len); SyncRequestVote *pMsg2 = syncRequestVoteBuild(); syncRequestVoteDeserialize(serialized, len, pMsg2); syncRequestVotePrint2((char *)"test2: syncRequestVoteSerialize -> syncRequestVoteDeserialize ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncRequestVoteDestroy(pMsg); syncRequestVoteDestroy(pMsg2); } @@ -53,7 +53,7 @@ void test3() { SyncRequestVote *pMsg2 = syncRequestVoteDeserialize2(serialized, len); syncRequestVotePrint2((char *)"test3: syncRequestVoteSerialize3 -> syncRequestVoteDeserialize2 ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncRequestVoteDestroy(pMsg); syncRequestVoteDestroy(pMsg2); } diff --git a/source/libs/sync/test/syncTimeoutTest.cpp b/source/libs/sync/test/syncTimeoutTest.cpp index 3f46ab5c7c..ab36f42d0d 100644 --- a/source/libs/sync/test/syncTimeoutTest.cpp +++ b/source/libs/sync/test/syncTimeoutTest.cpp @@ -30,13 +30,13 @@ void test1() { void test2() { SyncTimeout *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)malloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncTimeoutSerialize(pMsg, serialized, len); SyncTimeout *pMsg2 = syncTimeoutBuild(); syncTimeoutDeserialize(serialized, len, pMsg2); syncTimeoutPrint2((char *)"test2: syncTimeoutSerialize -> syncTimeoutDeserialize ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncTimeoutDestroy(pMsg); syncTimeoutDestroy(pMsg2); } @@ -48,7 +48,7 @@ void test3() { SyncTimeout *pMsg2 = syncTimeoutDeserialize2(serialized, len); syncTimeoutPrint2((char *)"test3: syncTimeoutSerialize3 -> syncTimeoutDeserialize2 ", pMsg2); - free(serialized); + taosMemoryFree(serialized); syncTimeoutDestroy(pMsg); syncTimeoutDestroy(pMsg2); } @@ -57,7 +57,7 @@ void test4() { SyncTimeout *pMsg = createMsg(); SRpcMsg rpcMsg; syncTimeout2RpcMsg(pMsg, &rpcMsg); - SyncTimeout *pMsg2 = (SyncTimeout *)malloc(rpcMsg.contLen); + SyncTimeout *pMsg2 = (SyncTimeout *)taosMemoryMalloc(rpcMsg.contLen); syncTimeoutFromRpcMsg(&rpcMsg, pMsg2); syncTimeoutPrint2((char *)"test4: syncTimeout2RpcMsg -> syncTimeoutFromRpcMsg ", pMsg2); diff --git a/source/libs/sync/test/syncVotesGrantedTest.cpp b/source/libs/sync/test/syncVotesGrantedTest.cpp index 588eb32ffd..6164aed351 100644 --- a/source/libs/sync/test/syncVotesGrantedTest.cpp +++ b/source/libs/sync/test/syncVotesGrantedTest.cpp @@ -67,7 +67,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } @@ -92,7 +92,7 @@ int main(int argc, char** argv) { char* serialized = syncNode2Str(pSyncNode); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); initRaftId(pSyncNode); @@ -104,7 +104,7 @@ int main(int argc, char** argv) { char* serialized = voteGranted2Str(pVotesGranted); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } SyncTerm term = 1234; @@ -114,7 +114,7 @@ int main(int argc, char** argv) { char* serialized = voteGranted2Str(pVotesGranted); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } for (int i = 0; i < replicaNum; ++i) { @@ -129,7 +129,7 @@ int main(int argc, char** argv) { char* serialized = voteGranted2Str(pVotesGranted); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } voteGrantedVote(pVotesGranted, reply); @@ -137,7 +137,7 @@ int main(int argc, char** argv) { char* serialized = voteGranted2Str(pVotesGranted); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } } @@ -147,7 +147,7 @@ int main(int argc, char** argv) { char* serialized = voteGranted2Str(pVotesGranted); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } voteGrantedDestroy(pVotesGranted); diff --git a/source/libs/sync/test/syncVotesRespondTest.cpp b/source/libs/sync/test/syncVotesRespondTest.cpp index 76fd6fab4e..39ba6253a1 100644 --- a/source/libs/sync/test/syncVotesRespondTest.cpp +++ b/source/libs/sync/test/syncVotesRespondTest.cpp @@ -67,7 +67,7 @@ void initRaftId(SSyncNode* pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char* s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } @@ -92,7 +92,7 @@ int main(int argc, char** argv) { char* serialized = syncNode2Str(pSyncNode); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); initRaftId(pSyncNode); @@ -104,7 +104,7 @@ int main(int argc, char** argv) { char* serialized = votesRespond2Str(pVotesRespond); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } SyncTerm term = 1234; @@ -114,7 +114,7 @@ int main(int argc, char** argv) { char* serialized = votesRespond2Str(pVotesRespond); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } for (int i = 0; i < replicaNum; ++i) { @@ -129,7 +129,7 @@ int main(int argc, char** argv) { char* serialized = votesRespond2Str(pVotesRespond); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } votesRespondAdd(pVotesRespond, reply); @@ -137,7 +137,7 @@ int main(int argc, char** argv) { char* serialized = votesRespond2Str(pVotesRespond); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } } @@ -147,7 +147,7 @@ int main(int argc, char** argv) { char* serialized = votesRespond2Str(pVotesRespond); assert(serialized != NULL); printf("%s\n", serialized); - free(serialized); + taosMemoryFree(serialized); } votesRespondDestory(pVotesRespond); diff --git a/source/libs/sync/test/syncWriteTest.cpp b/source/libs/sync/test/syncWriteTest.cpp index 732bcf140b..a3c24f69ff 100644 --- a/source/libs/sync/test/syncWriteTest.cpp +++ b/source/libs/sync/test/syncWriteTest.cpp @@ -54,7 +54,7 @@ void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, boo } void initFsm() { - pFsm = (SSyncFSM *)malloc(sizeof(SSyncFSM)); + pFsm = (SSyncFSM *)taosMemoryMalloc(sizeof(SSyncFSM)); pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; @@ -118,16 +118,16 @@ void initRaftId(SSyncNode *pSyncNode) { ids[i] = pSyncNode->replicasId[i]; char *s = syncUtilRaftId2Str(&ids[i]); printf("raftId[%d] : %s\n", i, s); - free(s); + taosMemoryFree(s); } } SRpcMsg *step0() { - SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + SRpcMsg *pMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); memset(pMsg, 0, sizeof(SRpcMsg)); pMsg->msgType = 9999; pMsg->contLen = 32; - pMsg->pCont = malloc(pMsg->contLen); + pMsg->pCont = taosMemoryMalloc(pMsg->contLen); snprintf((char *)(pMsg->pCont), pMsg->contLen, "hello, world"); return pMsg; } diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index c6e8c9dca9..f9dec34d12 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -73,7 +73,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S *ppBt = NULL; - pBt = (SBTree *)calloc(1, sizeof(*pBt)); + pBt = (SBTree *)taosMemoryCalloc(1, sizeof(*pBt)); if (pBt == NULL) { return -1; } @@ -107,7 +107,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S // TODO: pBt->root ret = tdbBtreeOpenImpl(pBt); if (ret < 0) { - free(pBt); + taosMemoryFree(pBt); return -1; } @@ -161,7 +161,7 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p // TODO: refact code here pBt = pCur->pBt; if (!pBt->pTmp) { - pBt->pTmp = (u8 *)malloc(pBt->pageSize); + pBt->pTmp = (u8 *)taosMemoryMalloc(pBt->pageSize); if (pBt->pTmp == NULL) { return -1; } diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 00f38a19bb..8360c925a8 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -30,7 +30,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF *ppDb = NULL; - pDb = (STDb *)calloc(1, sizeof(*pDb)); + pDb = (STDb *)taosMemoryCalloc(1, sizeof(*pDb)); if (pDb == NULL) { return -1; } diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 9a4dcdbcd5..fc9861ff8f 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -27,7 +27,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) dsize = strlen(rootDir); zsize = sizeof(*pEnv) + dsize * 2 + strlen(TDB_JOURNAL_NAME) + 3; - pPtr = (uint8_t *)calloc(1, zsize); + pPtr = (uint8_t *)taosMemoryCalloc(1, zsize); if (pPtr == NULL) { return -1; } diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 9d7181c1da..c9708ababd 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -65,7 +65,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { void *pPtr; SPage *pPgHdr; - pCache = (SPCache *)calloc(1, sizeof(*pCache)); + pCache = (SPCache *)taosMemoryCalloc(1, sizeof(*pCache)); if (pCache == NULL) { return -1; } @@ -74,7 +74,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { pCache->cacheSize = cacheSize; if (tdbPCacheOpenImpl(pCache) < 0) { - free(pCache); + taosMemoryFree(pCache); return -1; } @@ -281,7 +281,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { // Open the hash table pCache->nPage = 0; pCache->nHash = pCache->cacheSize; - pCache->pgHash = (SPage **)calloc(pCache->nHash, sizeof(SPage *)); + pCache->pgHash = (SPage **)taosMemoryCalloc(pCache->nHash, sizeof(SPage *)); if (pCache->pgHash == NULL) { // TODO return -1; @@ -301,9 +301,9 @@ int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; } static void *tdbOsMalloc(void *arg, size_t size) { void *ptr; - ptr = malloc(size); + ptr = taosMemoryMalloc(size); return ptr; } -static void tdbOsFree(void *arg, void *ptr) { free(ptr); } \ No newline at end of file +static void tdbOsFree(void *arg, void *ptr) { taosMemoryFree(ptr); } \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index ac0bc15e1d..a181c27926 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -60,7 +60,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { zsize = sizeof(*pPager) /* SPager */ + fsize + 1 /* dbFileName */ + fsize + 8 + 1; /* jFileName */ - pPtr = (uint8_t *)calloc(1, zsize); + pPtr = (uint8_t *)taosMemoryCalloc(1, zsize); if (pPtr == NULL) { return -1; } diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index bfe7904a63..e50045d30b 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -30,7 +30,7 @@ STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk) { return NULL; } - STfs *pTfs = calloc(1, sizeof(STfs)); + STfs *pTfs = taosMemoryCalloc(1, sizeof(STfs)); if (pTfs == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -86,7 +86,7 @@ void tfsClose(STfs *pTfs) { taosHashCleanup(pTfs->hash); taosThreadSpinDestroy(&pTfs->lock); - free(pTfs); + taosMemoryFree(pTfs); } void tfsUpdateSize(STfs *pTfs) { @@ -184,7 +184,7 @@ void *tfsDecodeFile(STfs *pTfs, void *buf, STfsFile *pFile) { tfsInitFile(pTfs, pFile, diskId, rname); - tfree(rname); + taosMemoryFreeClear(rname); return buf; } @@ -242,12 +242,12 @@ int32_t tfsMkdirRecurAt(STfs *pTfs, const char *rname, SDiskID diskId) { char *dir = strdup(taosDirName(s)); if (tfsMkdirRecurAt(pTfs, dir, diskId) < 0) { - free(s); - free(dir); + taosMemoryFree(s); + taosMemoryFree(dir); return -1; } - free(s); - free(dir); + taosMemoryFree(s); + taosMemoryFree(dir); if (tfsMkdirAt(pTfs, rname, diskId) < 0) { return -1; @@ -311,7 +311,7 @@ int32_t tfsRename(STfs *pTfs, char *orname, char *nrname) { } STfsDir *tfsOpendir(STfs *pTfs, const char *rname) { - STfsDir *pDir = calloc(1, sizeof(STfsDir)); + STfsDir *pDir = taosMemoryCalloc(1, sizeof(STfsDir)); if (pDir == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -323,7 +323,7 @@ STfsDir *tfsOpendir(STfs *pTfs, const char *rname) { tstrncpy(pDir->dirname, rname, TSDB_FILENAME_LEN); if (tfsOpendirImpl(pTfs, pDir) < 0) { - free(pDir); + taosMemoryFree(pDir); return NULL; } @@ -369,7 +369,7 @@ void tfsClosedir(STfsDir *pTfsDir) { taosCloseDir(pTfsDir->pDir); pTfsDir->pDir = NULL; } - free(pTfsDir); + taosMemoryFree(pTfsDir); } } diff --git a/source/libs/tfs/src/tfsDisk.c b/source/libs/tfs/src/tfsDisk.c index 52396db3be..ff40529ab2 100644 --- a/source/libs/tfs/src/tfsDisk.c +++ b/source/libs/tfs/src/tfsDisk.c @@ -17,7 +17,7 @@ #include "tfsInt.h" STfsDisk *tfsNewDisk(int32_t level, int32_t id, const char *path) { - STfsDisk *pDisk = calloc(1, sizeof(STfsDisk)); + STfsDisk *pDisk = taosMemoryCalloc(1, sizeof(STfsDisk)); if (pDisk == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -25,7 +25,7 @@ STfsDisk *tfsNewDisk(int32_t level, int32_t id, const char *path) { pDisk->path = strdup(path); if (pDisk->path == NULL) { - free(pDisk); + taosMemoryFree(pDisk); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -38,8 +38,8 @@ STfsDisk *tfsNewDisk(int32_t level, int32_t id, const char *path) { STfsDisk *tfsFreeDisk(STfsDisk *pDisk) { if (pDisk != NULL) { - free(pDisk->path); - free(pDisk); + taosMemoryFree(pDisk->path); + taosMemoryFree(pDisk); } return NULL; diff --git a/source/libs/tfs/test/tfsTest.cpp b/source/libs/tfs/test/tfsTest.cpp index 9cb914a670..1a093c3877 100644 --- a/source/libs/tfs/test/tfsTest.cpp +++ b/source/libs/tfs/test/tfsTest.cpp @@ -196,7 +196,7 @@ TEST_F(TfsTest, 04_File) { { int32_t size = 1024; - void *ret = malloc(size + sizeof(size_t)); + void *ret = taosMemoryMalloc(size + sizeof(size_t)); *(size_t *)ret = size; void *buf = (void *)((char *)ret + sizeof(size_t)); diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 8cfde8267d..eaca66aeab 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -281,14 +281,14 @@ void* transCtxDumpVal(STransCtx* ctx, int32_t key); // queue sending msgs typedef struct { SArray* q; - void (*free)(void* arg); + void (*freeFunc)(const void* arg); } STransQueue; /* * init queue * note: queue'size is small, default 1 */ -void transQueueInit(STransQueue* queue, void (*free)(void* arg)); +void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)); /* * put arg into queue diff --git a/source/libs/transport/src/rpcCache.c b/source/libs/transport/src/rpcCache.c index d629f6dba4..e02de2d8b9 100644 --- a/source/libs/transport/src/rpcCache.c +++ b/source/libs/transport/src/rpcCache.c @@ -60,21 +60,21 @@ void *rpcOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl, connHashMemPool = taosMemPoolInit(maxSessions, sizeof(SConnHash)); if (connHashMemPool == 0) return NULL; - connHashList = calloc(sizeof(SConnHash *), maxSessions); + connHashList = taosMemoryCalloc(sizeof(SConnHash *), maxSessions); if (connHashList == 0) { taosMemPoolCleanUp(connHashMemPool); return NULL; } - pCache = malloc(sizeof(SConnCache)); + pCache = taosMemoryMalloc(sizeof(SConnCache)); if (pCache == NULL) { taosMemPoolCleanUp(connHashMemPool); - free(connHashList); + taosMemoryFree(connHashList); return NULL; } memset(pCache, 0, sizeof(SConnCache)); - pCache->count = calloc(sizeof(int), maxSessions); + pCache->count = taosMemoryCalloc(sizeof(int), maxSessions); pCache->total = 0; pCache->keepTimer = keepTimer; pCache->maxSessions = maxSessions; @@ -82,7 +82,7 @@ void *rpcOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl, pCache->connHashList = connHashList; pCache->cleanFp = cleanFp; pCache->tmrCtrl = tmrCtrl; - pCache->lockedBy = calloc(sizeof(int64_t), maxSessions); + pCache->lockedBy = taosMemoryCalloc(sizeof(int64_t), maxSessions); taosTmrReset(rpcCleanConnCache, (int32_t)(pCache->keepTimer * 2), pCache, pCache->tmrCtrl, &pCache->pTimer); taosThreadMutexInit(&pCache->mutex, NULL); @@ -102,16 +102,16 @@ void rpcCloseConnCache(void *handle) { if (pCache->connHashMemPool) taosMemPoolCleanUp(pCache->connHashMemPool); - tfree(pCache->connHashList); - tfree(pCache->count); - tfree(pCache->lockedBy); + taosMemoryFreeClear(pCache->connHashList); + taosMemoryFreeClear(pCache->count); + taosMemoryFreeClear(pCache->lockedBy); taosThreadMutexUnlock(&pCache->mutex); taosThreadMutexDestroy(&pCache->mutex); memset(pCache, 0, sizeof(SConnCache)); - free(pCache); + taosMemoryFree(pCache); } void rpcAddConnIntoCache(void *handle, void *data, char *fqdn, uint16_t port, int8_t connType) { diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 98b24ac3c7..6beda5bfed 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -208,7 +208,7 @@ static void rpcDecRef(SRpcInfo *pRpc); static void rpcFree(void *p) { tTrace("free mem: %p", p); - free(p); + taosMemoryFree(p); } static void rpcInitImp(void) { @@ -240,7 +240,7 @@ void *rpcOpen(const SRpcInit *pInit) { // taosThreadOnce(&tsRpcInit, rpcInit); - pRpc = (SRpcInfo *)calloc(1, sizeof(SRpcInfo)); + pRpc = (SRpcInfo *)taosMemoryCalloc(1, sizeof(SRpcInfo)); if (pRpc == NULL) return NULL; if (pInit->label) tstrncpy(pRpc->label, pInit->label, tListLen(pInit->label)); @@ -270,7 +270,7 @@ void *rpcOpen(const SRpcInit *pInit) { atomic_add_fetch_32(&tsRpcNum, 1); size_t size = sizeof(SRpcConn) * pRpc->sessions; - pRpc->connList = (SRpcConn *)calloc(1, size); + pRpc->connList = (SRpcConn *)taosMemoryCalloc(1, size); if (pRpc->connList == NULL) { tError("%s failed to allocate memory for taos connections, size:%" PRId64, pRpc->label, (int64_t)size); rpcClose(pRpc); @@ -350,7 +350,7 @@ void rpcClose(void *param) { void *rpcMallocCont(int contLen) { int size = contLen + RPC_MSG_OVERHEAD; - char *start = (char *)calloc(1, (size_t)size); + char *start = (char *)taosMemoryCalloc(1, (size_t)size); if (start == NULL) { tError("failed to malloc msg, size:%d", size); return NULL; @@ -364,7 +364,7 @@ void *rpcMallocCont(int contLen) { void rpcFreeCont(void *cont) { if (cont) { char *temp = ((char *)cont) - sizeof(SRpcHead) - sizeof(SRpcReqContext); - free(temp); + taosMemoryFree(temp); tTrace("free mem: %p", temp); } } @@ -374,12 +374,12 @@ void *rpcReallocCont(void *ptr, int contLen) { char *start = ((char *)ptr) - sizeof(SRpcReqContext) - sizeof(SRpcHead); if (contLen == 0) { - free(start); + taosMemoryFree(start); return NULL; } int size = contLen + RPC_MSG_OVERHEAD; - start = realloc(start, size); + start = taosMemoryRealloc(start, size); if (start == NULL) { tError("failed to realloc cont, size:%d", size); return NULL; @@ -574,7 +574,7 @@ void rpcCancelRequest(int64_t rid) { static void rpcFreeMsg(void *msg) { if (msg) { char *temp = (char *)msg - sizeof(SRpcReqContext); - free(temp); + taosMemoryFree(temp); tTrace("free mem: %p", temp); } } @@ -1039,7 +1039,7 @@ static void doRpcReportBrokenLinkToServer(void *param, void *id) { SRpcConn *pConn = (SRpcConn *)(pRpcMsg->handle); SRpcInfo *pRpc = pConn->pRpc; (*(pRpc->cfp))(pRpc->parent, pRpcMsg, NULL); - free(pRpcMsg); + taosMemoryFree(pRpcMsg); } static void rpcReportBrokenLinkToServer(SRpcConn *pConn) { SRpcInfo *pRpc = pConn->pRpc; @@ -1049,7 +1049,7 @@ static void rpcReportBrokenLinkToServer(SRpcConn *pConn) { rpcAddRef(pRpc); tDebug("%s, notify the server app, connection is gone", pConn->info); - SRpcMsg *rpcMsg = malloc(sizeof(SRpcMsg)); + SRpcMsg *rpcMsg = taosMemoryMalloc(sizeof(SRpcMsg)); rpcMsg->pCont = pConn->pReqMsg; // pReqMsg is re-used to store the APP context from server rpcMsg->contLen = pConn->reqMsgLen; // reqMsgLen is re-used to store the APP context length rpcMsg->ahandle = pConn->ahandle; @@ -1061,7 +1061,7 @@ static void rpcReportBrokenLinkToServer(SRpcConn *pConn) { if (pRpc->cfp) { taosTmrStart(doRpcReportBrokenLinkToServer, 0, rpcMsg, pRpc->tmrCtrl); } else { - free(rpcMsg); + taosMemoryFree(rpcMsg); } } @@ -1484,7 +1484,7 @@ static int32_t rpcCompressRpcMsg(char *pCont, int32_t contLen) { return contLen; } - char *buf = malloc(contLen + overhead + 8); // 8 extra bytes + char *buf = taosMemoryMalloc(contLen + overhead + 8); // 8 extra bytes if (buf == NULL) { tError("failed to allocate memory for rpc msg compression, contLen:%d", contLen); return contLen; @@ -1510,7 +1510,7 @@ static int32_t rpcCompressRpcMsg(char *pCont, int32_t contLen) { finalLen = contLen; } - free(buf); + taosMemoryFree(buf); return finalLen; } @@ -1526,7 +1526,7 @@ static SRpcHead *rpcDecompressRpcMsg(SRpcHead *pHead) { int contLen = htonl(pComp->contLen); // prepare the temporary buffer to decompress message - char *temp = (char *)malloc(contLen + RPC_MSG_OVERHEAD); + char *temp = (char *)taosMemoryMalloc(contLen + RPC_MSG_OVERHEAD); pNewHead = (SRpcHead *)(temp + sizeof(SRpcReqContext)); // reserve SRpcReqContext if (pNewHead) { @@ -1671,10 +1671,10 @@ static void rpcDecRef(SRpcInfo *pRpc) { taosTmrCleanUp(pRpc->tmrCtrl); taosIdPoolCleanUp(pRpc->idPool); - tfree(pRpc->connList); + taosMemoryFreeClear(pRpc->connList); taosThreadMutexDestroy(&pRpc->mutex); tDebug("%s rpc resources are released", pRpc->label); - tfree(pRpc); + taosMemoryFreeClear(pRpc); atomic_sub_fetch_32(&tsRpcNum, 1); } diff --git a/source/libs/transport/src/rpcTcp.c b/source/libs/transport/src/rpcTcp.c index 4b1700a10f..52c5ddcf63 100644 --- a/source/libs/transport/src/rpcTcp.c +++ b/source/libs/transport/src/rpcTcp.c @@ -78,7 +78,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread SServerObj *pServerObj; SThreadObj *pThreadObj; - pServerObj = (SServerObj *)calloc(sizeof(SServerObj), 1); + pServerObj = (SServerObj *)taosMemoryCalloc(sizeof(SServerObj), 1); if (pServerObj == NULL) { tError("TCP:%s no enough memory", label); terrno = TAOS_SYSTEM_ERROR(errno); @@ -92,11 +92,11 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread tstrncpy(pServerObj->label, label, sizeof(pServerObj->label)); pServerObj->numOfThreads = numOfThreads; - pServerObj->pThreadObj = (SThreadObj **)calloc(sizeof(SThreadObj *), numOfThreads); + pServerObj->pThreadObj = (SThreadObj **)taosMemoryCalloc(sizeof(SThreadObj *), numOfThreads); if (pServerObj->pThreadObj == NULL) { tError("TCP:%s no enough memory", label); terrno = TAOS_SYSTEM_ERROR(errno); - free(pServerObj); + taosMemoryFree(pServerObj); return NULL; } @@ -107,13 +107,13 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread // initialize parameters in case it may encounter error later for (int i = 0; i < numOfThreads; ++i) { - pThreadObj = (SThreadObj *)calloc(sizeof(SThreadObj), 1); + pThreadObj = (SThreadObj *)taosMemoryCalloc(sizeof(SThreadObj), 1); if (pThreadObj == NULL) { tError("TCP:%s no enough memory", label); terrno = TAOS_SYSTEM_ERROR(errno); - for (int j = 0; j < i; ++j) free(pServerObj->pThreadObj[j]); - free(pServerObj->pThreadObj); - free(pServerObj); + for (int j = 0; j < i; ++j) taosMemoryFree(pServerObj->pThreadObj[j]); + taosMemoryFree(pServerObj->pThreadObj); + taosMemoryFree(pServerObj); return NULL; } @@ -222,8 +222,8 @@ void taosCleanUpTcpServer(void *handle) { tDebug("%s TCP server is cleaned up", pServerObj->label); - tfree(pServerObj->pThreadObj); - tfree(pServerObj); + taosMemoryFreeClear(pServerObj->pThreadObj); + taosMemoryFreeClear(pServerObj); } static void *taosAcceptTcpConnection(void *arg) { @@ -290,7 +290,7 @@ static void *taosAcceptTcpConnection(void *arg) { } void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle) { - SClientObj *pClientObj = (SClientObj *)calloc(1, sizeof(SClientObj)); + SClientObj *pClientObj = (SClientObj *)taosMemoryCalloc(1, sizeof(SClientObj)); if (pClientObj == NULL) { tError("TCP:%s no enough memory", label); terrno = TAOS_SYSTEM_ERROR(errno); @@ -299,10 +299,10 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread tstrncpy(pClientObj->label, label, sizeof(pClientObj->label)); pClientObj->numOfThreads = numOfThreads; - pClientObj->pThreadObj = (SThreadObj **)calloc(numOfThreads, sizeof(SThreadObj *)); + pClientObj->pThreadObj = (SThreadObj **)taosMemoryCalloc(numOfThreads, sizeof(SThreadObj *)); if (pClientObj->pThreadObj == NULL) { tError("TCP:%s no enough memory", label); - tfree(pClientObj); + taosMemoryFreeClear(pClientObj); terrno = TAOS_SYSTEM_ERROR(errno); } @@ -312,12 +312,12 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); for (int i = 0; i < numOfThreads; ++i) { - SThreadObj *pThreadObj = (SThreadObj *)calloc(1, sizeof(SThreadObj)); + SThreadObj *pThreadObj = (SThreadObj *)taosMemoryCalloc(1, sizeof(SThreadObj)); if (pThreadObj == NULL) { tError("TCP:%s no enough memory", label); terrno = TAOS_SYSTEM_ERROR(errno); - for (int j = 0; j < i; ++j) free(pClientObj->pThreadObj[j]); - free(pClientObj); + for (int j = 0; j < i; ++j) taosMemoryFree(pClientObj->pThreadObj[j]); + taosMemoryFree(pClientObj); taosThreadAttrDestroy(&thattr); return NULL; } @@ -378,8 +378,8 @@ void taosCleanUpTcpClient(void *chandle) { } tDebug("%s TCP client is cleaned up", pClientObj->label); - tfree(pClientObj->pThreadObj); - tfree(pClientObj); + taosMemoryFreeClear(pClientObj->pThreadObj); + taosMemoryFreeClear(pClientObj); } void *taosOpenTcpClientConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port) { @@ -477,9 +477,9 @@ static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) { msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen); int32_t size = msgLen + tsRpcOverhead; - buffer = malloc(size); + buffer = taosMemoryMalloc(size); if (NULL == buffer) { - tError("%s %p TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen); + tError("%s %p TCP taosMemoryMalloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen); return -1; } else { tTrace("%s %p read data, FD:%p TCP malloc mem:%p", pThreadObj->label, pFdObj->thandle, pFdObj, buffer); @@ -491,7 +491,7 @@ static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) { if (leftLen != retLen) { tError("%s %p read error, leftLen:%d retLen:%d FD:%p", pThreadObj->label, pFdObj->thandle, leftLen, retLen, pFdObj); - free(buffer); + taosMemoryFree(buffer); return -1; } @@ -507,7 +507,7 @@ static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) { pInfo->connType = RPC_CONN_TCP; if (pFdObj->closedByApp) { - free(buffer); + taosMemoryFree(buffer); return -1; } @@ -580,7 +580,7 @@ static void *taosProcessTcpData(void *param) { taosThreadMutexDestroy(&(pThreadObj->mutex)); tDebug("%s TCP thread exits ...", pThreadObj->label); - tfree(pThreadObj); + taosMemoryFreeClear(pThreadObj); return NULL; } @@ -588,7 +588,7 @@ static void *taosProcessTcpData(void *param) { static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, TdSocketPtr pSocket) { struct epoll_event event; - SFdObj *pFdObj = (SFdObj *)calloc(sizeof(SFdObj), 1); + SFdObj *pFdObj = (SFdObj *)taosMemoryCalloc(sizeof(SFdObj), 1); if (pFdObj == NULL) { return NULL; } @@ -601,7 +601,7 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, TdSocketPtr pSocket) { event.events = EPOLLIN | EPOLLRDHUP; event.data.ptr = pFdObj; if (taosCtlEpoll(pThreadObj->pEpoll, EPOLL_CTL_ADD, pSocket, &event) < 0) { - tfree(pFdObj); + taosMemoryFreeClear(pFdObj); terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -652,6 +652,6 @@ static void taosFreeFdObj(SFdObj *pFdObj) { tDebug("%s %p TCP connection is closed, FD:%p numOfFds:%d", pThreadObj->label, pFdObj->thandle, pFdObj, pThreadObj->numOfFds); - tfree(pFdObj); + taosMemoryFreeClear(pFdObj); } #endif \ No newline at end of file diff --git a/source/libs/transport/src/rpcUdp.c b/source/libs/transport/src/rpcUdp.c index af26761603..359a94011d 100644 --- a/source/libs/transport/src/rpcUdp.c +++ b/source/libs/transport/src/rpcUdp.c @@ -62,7 +62,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads SUdpConnSet *pSet; int size = (int)sizeof(SUdpConnSet) + threads * (int)sizeof(SUdpConn); - pSet = (SUdpConnSet *)malloc((size_t)size); + pSet = (SUdpConnSet *)taosMemoryMalloc((size_t)size); if (pSet == NULL) { tError("%s failed to allocate UdpConn", label); terrno = TAOS_SYSTEM_ERROR(errno); @@ -92,7 +92,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads break; } - pConn->buffer = malloc(RPC_MAX_UDP_SIZE); + pConn->buffer = taosMemoryMalloc(RPC_MAX_UDP_SIZE); if (NULL == pConn->buffer) { tError("%s failed to malloc recv buffer", label); break; @@ -148,7 +148,7 @@ void taosStopUdpConnection(void *handle) { if (taosCheckPthreadValid(pConn->thread)) { taosThreadJoin(pConn->thread, NULL); } - tfree(pConn->buffer); + taosMemoryFreeClear(pConn->buffer); // tTrace("%s UDP thread is closed, index:%d", pConn->label, i); } @@ -167,7 +167,7 @@ void taosCleanUpUdpConnection(void *handle) { } tDebug("%s UDP is cleaned up", pSet->label); - tfree(pSet); + taosMemoryFreeClear(pSet); } void *taosOpenUdpConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port) { @@ -219,7 +219,7 @@ static void *taosRecvUdpData(void *param) { } int32_t size = dataLen + tsRpcOverhead; - char * tmsg = malloc(size); + char * tmsg = taosMemoryMalloc(size); if (NULL == tmsg) { tError("%s failed to allocate memory, size:%" PRId64, pConn->label, (int64_t)dataLen); continue; diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 4e2cb83527..90f15dd7d0 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -47,7 +47,7 @@ static int32_t taosBuildHttpHeader(const char* server, int32_t contLen, char* pH int32_t taosCompressHttpRport(char* pSrc, int32_t srcLen) { int32_t code = -1; int32_t destLen = srcLen; - void* pDest = malloc(destLen); + void* pDest = taosMemoryMalloc(destLen); if (pDest == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -109,7 +109,7 @@ _OVER: code = gzipStream.total_out; } - free(pDest); + taosMemoryFree(pDest); return code; } @@ -145,7 +145,7 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32 uv_tcp_t socket_tcp = {0}; uv_loop_t* loop = uv_default_loop(); uv_tcp_init(loop, &socket_tcp); - uv_connect_t* connect = (uv_connect_t*)malloc(sizeof(uv_connect_t)); + uv_connect_t* connect = (uv_connect_t*)taosMemoryMalloc(sizeof(uv_connect_t)); if (flag == HTTP_GZIP) { int32_t dstLen = taosCompressHttpRport(pCont, contLen); @@ -168,7 +168,7 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32 terrno = 0; uv_run(loop, UV_RUN_DEFAULT); uv_loop_close(loop); - free(connect); + taosMemoryFree(connect); return terrno; } diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 9d0fba4885..ebb90338cd 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -28,7 +28,7 @@ void (*taosUnRefHandle[])(void* handle) = {transUnrefSrvHandle, transUnrefCliHan void (*transReleaseHandle[])(void* handle) = {transReleaseSrvHandle, transReleaseCliHandle}; void* rpcOpen(const SRpcInit* pInit) { - SRpcInfo* pRpc = calloc(1, sizeof(SRpcInfo)); + SRpcInfo* pRpc = taosMemoryCalloc(1, sizeof(SRpcInfo)); if (pRpc == NULL) { return NULL; } @@ -61,13 +61,13 @@ void* rpcOpen(const SRpcInit* pInit) { void rpcClose(void* arg) { SRpcInfo* pRpc = (SRpcInfo*)arg; (*taosCloseHandle[pRpc->connType])(pRpc->tcphandle); - free(pRpc); + taosMemoryFree(pRpc); return; } void* rpcMallocCont(int contLen) { int size = contLen + TRANS_MSG_OVERHEAD; - char* start = (char*)calloc(1, (size_t)size); + char* start = (char*)taosMemoryCalloc(1, (size_t)size); if (start == NULL) { tError("failed to malloc msg, size:%d", size); return NULL; @@ -81,7 +81,7 @@ void rpcFreeCont(void* cont) { if (cont == NULL) { return; } - free((char*)cont - TRANS_MSG_OVERHEAD); + taosMemoryFree((char*)cont - TRANS_MSG_OVERHEAD); } void* rpcReallocCont(void* ptr, int contLen) { if (ptr == NULL) { @@ -89,7 +89,7 @@ void* rpcReallocCont(void* ptr, int contLen) { } char* st = (char*)ptr - TRANS_MSG_OVERHEAD; int sz = contLen + TRANS_MSG_OVERHEAD; - st = realloc(st, sz); + st = taosMemoryRealloc(st, sz); if (st == NULL) { return NULL; } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c0ee9b9ca5..a0e8af1db9 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -429,9 +429,9 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } static SCliConn* cliCreateConn(SCliThrdObj* pThrd) { - SCliConn* conn = calloc(1, sizeof(SCliConn)); + SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); // read/write stream handle - conn->stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t)); + conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); uv_tcp_init(pThrd->loop, (uv_tcp_t*)(conn->stream)); conn->stream->data = conn; @@ -456,12 +456,12 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { } static void cliDestroy(uv_handle_t* handle) { SCliConn* conn = handle->data; - free(conn->ip); - free(conn->stream); + taosMemoryFree(conn->ip); + taosMemoryFree(conn->stream); transCtxCleanup(&conn->ctx); transQueueDestroy(&conn->cliMsgs); tTrace("%s cli conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); - free(conn); + taosMemoryFree(conn); } static bool cliHandleNoResp(SCliConn* conn) { bool res = false; @@ -519,7 +519,7 @@ void cliSend(SCliConn* pConn) { int msgLen = transMsgLenFromCont(pMsg->contLen); if (!pConn->secured) { - char* buf = calloc(1, msgLen + sizeof(STransUserMsg)); + char* buf = taosMemoryCalloc(1, msgLen + sizeof(STransUserMsg)); memcpy(buf, (char*)pHead, msgLen); STransUserMsg* uMsg = (STransUserMsg*)(buf + msgLen); @@ -697,12 +697,12 @@ static void* cliWorkThread(void* arg) { } void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) { - SCliObj* cli = calloc(1, sizeof(SCliObj)); + SCliObj* cli = taosMemoryCalloc(1, sizeof(SCliObj)); STrans* pTransInst = shandle; memcpy(cli->label, label, strlen(label)); cli->numOfThreads = numOfThreads; - cli->pThreadObj = (SCliThrdObj**)calloc(cli->numOfThreads, sizeof(SCliThrdObj*)); + cli->pThreadObj = (SCliThrdObj**)taosMemoryCalloc(cli->numOfThreads, sizeof(SCliThrdObj*)); for (int i = 0; i < cli->numOfThreads; i++) { SCliThrdObj* pThrd = createThrdObj(); @@ -731,16 +731,16 @@ static void destroyCmsg(SCliMsg* pMsg) { } transDestroyConnCtx(pMsg->ctx); destroyUserdata(&pMsg->msg); - free(pMsg); + taosMemoryFree(pMsg); } static SCliThrdObj* createThrdObj() { - SCliThrdObj* pThrd = (SCliThrdObj*)calloc(1, sizeof(SCliThrdObj)); + SCliThrdObj* pThrd = (SCliThrdObj*)taosMemoryCalloc(1, sizeof(SCliThrdObj)); QUEUE_INIT(&pThrd->msg); taosThreadMutexInit(&pThrd->msgMtx, NULL); - pThrd->loop = (uv_loop_t*)malloc(sizeof(uv_loop_t)); + pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); uv_loop_init(pThrd->loop); pThrd->asyncPool = transCreateAsyncPool(pThrd->loop, 5, pThrd, cliAsyncCb); @@ -763,20 +763,20 @@ static void destroyThrdObj(SCliThrdObj* pThrd) { transDestroyAsyncPool(pThrd->asyncPool); uv_timer_stop(&pThrd->timer); - free(pThrd->loop); - free(pThrd); + taosMemoryFree(pThrd->loop); + taosMemoryFree(pThrd); } static void transDestroyConnCtx(STransConnCtx* ctx) { if (ctx != NULL) { - free(ctx->ip); + taosMemoryFree(ctx->ip); } - free(ctx); + taosMemoryFree(ctx); } // void cliSendQuit(SCliThrdObj* thrd) { // cli can stop gracefully - SCliMsg* msg = calloc(1, sizeof(SCliMsg)); + SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg)); msg->type = Quit; transSendAsync(thrd->asyncPool, &msg->q); } @@ -795,8 +795,8 @@ void transCloseClient(void* arg) { cliSendQuit(cli->pThreadObj[i]); destroyThrdObj(cli->pThreadObj[i]); } - free(cli->pThreadObj); - free(cli); + taosMemoryFree(cli->pThreadObj); + taosMemoryFree(cli); } void transRefCliHandle(void* handle) { if (handle == NULL) { @@ -822,7 +822,7 @@ void transReleaseCliHandle(void* handle) { } STransMsg tmsg = {.handle = handle}; - SCliMsg* cmsg = calloc(1, sizeof(SCliMsg)); + SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg)); cmsg->msg = tmsg; cmsg->type = Release; @@ -836,7 +836,7 @@ void transSendRequest(void* shandle, const char* ip, uint32_t port, STransMsg* p index = cliRBChoseIdx(pTransInst); } - STransConnCtx* pCtx = calloc(1, sizeof(STransConnCtx)); + STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); pCtx->ahandle = pMsg->ahandle; pCtx->msgType = pMsg->msgType; pCtx->ip = strdup(ip); @@ -848,7 +848,7 @@ void transSendRequest(void* shandle, const char* ip, uint32_t port, STransMsg* p } assert(pTransInst->connType == TAOS_CONN_CLIENT); - SCliMsg* cliMsg = calloc(1, sizeof(SCliMsg)); + SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); cliMsg->ctx = pCtx; cliMsg->msg = *pMsg; cliMsg->st = taosGetTimestampUs(); @@ -867,17 +867,17 @@ void transSendRecv(void* shandle, const char* ip, uint32_t port, STransMsg* pReq index = cliRBChoseIdx(pTransInst); } - STransConnCtx* pCtx = calloc(1, sizeof(STransConnCtx)); + STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); pCtx->ahandle = pReq->ahandle; pCtx->msgType = pReq->msgType; pCtx->ip = strdup(ip); pCtx->port = port; pCtx->hThrdIdx = index; - pCtx->pSem = calloc(1, sizeof(tsem_t)); + pCtx->pSem = taosMemoryCalloc(1, sizeof(tsem_t)); pCtx->pRsp = pRsp; tsem_init(pCtx->pSem, 0, 0); - SCliMsg* cliMsg = calloc(1, sizeof(SCliMsg)); + SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); cliMsg->ctx = pCtx; cliMsg->msg = *pReq; cliMsg->st = taosGetTimestampUs(); @@ -888,7 +888,7 @@ void transSendRecv(void* shandle, const char* ip, uint32_t port, STransMsg* pReq tsem_t* pSem = pCtx->pSem; tsem_wait(pSem); tsem_destroy(pSem); - free(pSem); + taosMemoryFree(pSem); } #endif diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 209475ca05..31ac1e1fbf 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -52,7 +52,7 @@ bool transCompressMsg(char* msg, int32_t len, int32_t* flen) { return succ; } - char* buf = malloc(len + overhead + 8); // 8 extra bytes + char* buf = taosMemoryMalloc(len + overhead + 8); // 8 extra bytes if (buf == NULL) { tError("failed to allocate memory for rpc msg compression, contLen:%d", len); *flen = len; @@ -78,7 +78,7 @@ bool transCompressMsg(char* msg, int32_t len, int32_t* flen) { *flen = len; succ = false; } - free(buf); + taosMemoryFree(buf); return succ; } bool transDecompressMsg(char* msg, int32_t len, int32_t* flen) { @@ -92,15 +92,15 @@ bool transDecompressMsg(char* msg, int32_t len, int32_t* flen) { } void transConnCtxDestroy(STransConnCtx* ctx) { - free(ctx->ip); - free(ctx); + taosMemoryFree(ctx->ip); + taosMemoryFree(ctx); } void transFreeMsg(void* msg) { if (msg == NULL) { return; } - free((char*)msg - sizeof(STransMsgHead)); + taosMemoryFree((char*)msg - sizeof(STransMsgHead)); } int transInitBuffer(SConnBuffer* buf) { @@ -123,7 +123,7 @@ int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) { SConnBuffer* p = connBuf; if (p->cap == 0) { - p->buf = (char*)calloc(CAPACITY, sizeof(char)); + p->buf = (char*)taosMemoryCalloc(CAPACITY, sizeof(char)); p->len = 0; p->cap = CAPACITY; p->total = -1; @@ -135,7 +135,7 @@ int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) { uvBuf->len = CAPACITY - p->len; } else { p->cap = p->total; - p->buf = realloc(p->buf, p->cap); + p->buf = taosMemoryRealloc(p->buf, p->cap); uvBuf->base = p->buf + p->len; uvBuf->len = p->cap - p->len; @@ -160,7 +160,7 @@ int transPackMsg(STransMsgHead* msgHead, bool sercured, bool auth) { return 0; } int transUnpackMsg(STransMsgHead* msgHead) { return 0; } int transDestroyBuffer(SConnBuffer* buf) { if (buf->cap > 0) { - tfree(buf->buf); + taosMemoryFreeClear(buf->buf); } transClearBuffer(buf); @@ -174,16 +174,16 @@ int transSetConnOption(uv_tcp_t* stream) { } SAsyncPool* transCreateAsyncPool(uv_loop_t* loop, int sz, void* arg, AsyncCB cb) { - SAsyncPool* pool = calloc(1, sizeof(SAsyncPool)); + SAsyncPool* pool = taosMemoryCalloc(1, sizeof(SAsyncPool)); pool->index = 0; pool->nAsync = sz; - pool->asyncs = calloc(1, sizeof(uv_async_t) * pool->nAsync); + pool->asyncs = taosMemoryCalloc(1, sizeof(uv_async_t) * pool->nAsync); for (int i = 0; i < pool->nAsync; i++) { uv_async_t* async = &(pool->asyncs[i]); uv_async_init(loop, async, cb); - SAsyncItem* item = calloc(1, sizeof(SAsyncItem)); + SAsyncItem* item = taosMemoryCalloc(1, sizeof(SAsyncItem)); item->pThrd = arg; QUEUE_INIT(&item->qmsg); taosThreadMutexInit(&item->mtx, NULL); @@ -198,10 +198,10 @@ void transDestroyAsyncPool(SAsyncPool* pool) { SAsyncItem* item = async->data; taosThreadMutexDestroy(&item->mtx); - free(item); + taosMemoryFree(item); } - free(pool->asyncs); - free(pool); + taosMemoryFree(pool->asyncs); + taosMemoryFree(pool); } int transSendAsync(SAsyncPool* pool, queue* q) { int idx = pool->index; @@ -235,7 +235,7 @@ void transCtxCleanup(STransCtx* ctx) { STransCtxVal* iter = taosHashIterate(ctx->args, NULL); while (iter) { - iter->free(iter->val); + iter->freeFunc(iter->val); iter = taosHashIterate(ctx->args, iter); } taosHashCleanup(ctx->args); @@ -256,7 +256,7 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) { STransCtxVal* dVal = taosHashGet(dst->args, key, klen); if (dVal) { - dVal->free(dVal->val); + dVal->freeFunc(dVal->val); } taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal)); iter = taosHashIterate(src->args, iter); @@ -271,14 +271,14 @@ void* transCtxDumpVal(STransCtx* ctx, int32_t key) { if (cVal == NULL) { return NULL; } - char* ret = calloc(1, cVal->len); + char* ret = taosMemoryCalloc(1, cVal->len); memcpy(ret, (char*)cVal->val, cVal->len); return (void*)ret; } -void transQueueInit(STransQueue* queue, void (*free)(void* arg)) { +void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) { queue->q = taosArrayInit(2, sizeof(void*)); - queue->free = free; + queue->freeFunc = freeFunc; } bool transQueuePush(STransQueue* queue, void* arg) { taosArrayPush(queue->q, &arg); @@ -308,10 +308,10 @@ bool transQueueEmpty(STransQueue* queue) { return taosArrayGetSize(queue->q) == 0; } void transQueueClear(STransQueue* queue) { - if (queue->free != NULL) { + if (queue->freeFunc != NULL) { for (int i = 0; i < taosArrayGetSize(queue->q); i++) { void* p = taosArrayGetP(queue->q, i); - queue->free(p); + queue->freeFunc(p); } } taosArrayClear(queue->q); diff --git a/source/libs/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index c6032a9569..d503c5b3d3 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -102,7 +102,7 @@ static const char* notify = "a"; tTrace("server conn %p received release request", conn); \ \ STransMsg tmsg = {.handle = (void*)conn, .code = 0}; \ - SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg)); \ + SSrvMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSrvMsg)); \ srvMsg->msg = tmsg; \ srvMsg->type = Release; \ srvMsg->pConn = conn; \ @@ -256,7 +256,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { } void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { buf->len = 2; - buf->base = calloc(1, sizeof(char) * buf->len); + buf->base = taosMemoryCalloc(1, sizeof(char) * buf->len); } void uvOnTimeoutCb(uv_timer_t* handle) { @@ -290,7 +290,7 @@ void uvOnSendCb(uv_write_t* req, int status) { memset(&conn->regArg, 0, sizeof(conn->regArg)); } transQueuePop(&conn->srvMsgs); - free(msg); + taosMemoryFree(msg); } else { uvStartSendRespInternal(msg); } @@ -308,7 +308,7 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) { } else { tError("fail to dispatch conn to work thread"); } - free(req); + taosMemoryFree(req); } static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) { @@ -380,7 +380,7 @@ static void destroySmsg(SSrvMsg* smsg) { return; } transFreeMsg(smsg->msg.pCont); - free(smsg); + taosMemoryFree(smsg); } static void destroyAllConn(SWorkThrdObj* pThrd) { while (!QUEUE_IS_EMPTY(&pThrd->conn)) { @@ -430,7 +430,7 @@ static void uvShutDownCb(uv_shutdown_t* req, int status) { tDebug("conn failed to shut down: %s", uv_err_name(status)); } uv_close((uv_handle_t*)req->handle, uvDestroyConn); - free(req); + taosMemoryFree(req); } void uvOnAcceptCb(uv_stream_t* stream, int status) { @@ -439,11 +439,11 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { } SServerObj* pObj = container_of(stream, SServerObj, server); - uv_tcp_t* cli = (uv_tcp_t*)malloc(sizeof(uv_tcp_t)); + uv_tcp_t* cli = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); uv_tcp_init(pObj->loop, cli); if (uv_accept(stream, (uv_stream_t*)cli) == 0) { - uv_write_t* wr = (uv_write_t*)malloc(sizeof(uv_write_t)); + uv_write_t* wr = (uv_write_t*)taosMemoryMalloc(sizeof(uv_write_t)); uv_buf_t buf = uv_buf_init((char*)notify, strlen(notify)); @@ -453,7 +453,7 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { uv_write2(wr, (uv_stream_t*)&(pObj->pipe[pObj->workerIdx][0]), &buf, 1, (uv_stream_t*)cli, uvOnPipeWriteCb); } else { uv_close((uv_handle_t*)cli, NULL); - free(cli); + taosMemoryFree(cli); } } void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { @@ -469,7 +469,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { // free memory allocated by assert(nread == strlen(notify)); assert(buf->base[0] == notify[0]); - free(buf->base); + taosMemoryFree(buf->base); SWorkThrdObj* pThrd = q->data; @@ -492,7 +492,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { pConn->hostThrd = pThrd; // init client handle - pConn->pTcp = (uv_tcp_t*)malloc(sizeof(uv_tcp_t)); + pConn->pTcp = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); uv_tcp_init(pThrd->loop, pConn->pTcp); pConn->pTcp->data = pConn; @@ -537,7 +537,7 @@ void* acceptThread(void* arg) { } static bool addHandleToWorkloop(void* arg) { SWorkThrdObj* pThrd = arg; - pThrd->loop = (uv_loop_t*)malloc(sizeof(uv_loop_t)); + pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); if (0 != uv_loop_init(pThrd->loop)) { return false; } @@ -569,7 +569,7 @@ static bool addHandleToAcceptloop(void* arg) { } // register an async here to quit server gracefully - srv->pAcceptAsync = calloc(1, sizeof(uv_async_t)); + srv->pAcceptAsync = taosMemoryCalloc(1, sizeof(uv_async_t)); uv_async_init(srv->loop, srv->pAcceptAsync, uvAcceptAsyncCb); srv->pAcceptAsync->data = srv; @@ -596,7 +596,7 @@ void* workerThread(void* arg) { static SSrvConn* createConn(void* hThrd) { SWorkThrdObj* pThrd = hThrd; - SSrvConn* pConn = (SSrvConn*)calloc(1, sizeof(SSrvConn)); + SSrvConn* pConn = (SSrvConn*)taosMemoryCalloc(1, sizeof(SSrvConn)); QUEUE_INIT(&pConn->queue); QUEUE_PUSH(&pThrd->conn, &pConn->queue); @@ -621,7 +621,7 @@ static void destroyConn(SSrvConn* conn, bool clear) { transQueueDestroy(&conn->srvMsgs); if (clear) { tTrace("server conn %p to be destroyed", conn); - uv_shutdown_t* req = malloc(sizeof(uv_shutdown_t)); + uv_shutdown_t* req = taosMemoryMalloc(sizeof(uv_shutdown_t)); uv_shutdown(req, (uv_stream_t*)conn->pTcp, uvShutDownCb); } } @@ -635,8 +635,8 @@ static void uvDestroyConn(uv_handle_t* handle) { tDebug("server conn %p destroy", conn); uv_timer_stop(&conn->pTimer); QUEUE_REMOVE(&conn->queue); - free(conn->pTcp); - // free(conn); + taosMemoryFree(conn->pTcp); + // taosMemoryFree(conn); if (thrd->quit && QUEUE_IS_EMPTY(&thrd->conn)) { uv_loop_close(thrd->loop); @@ -645,22 +645,22 @@ static void uvDestroyConn(uv_handle_t* handle) { } void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) { - SServerObj* srv = calloc(1, sizeof(SServerObj)); - srv->loop = (uv_loop_t*)malloc(sizeof(uv_loop_t)); + SServerObj* srv = taosMemoryCalloc(1, sizeof(SServerObj)); + srv->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); srv->numOfThreads = numOfThreads; srv->workerIdx = 0; - srv->pThreadObj = (SWorkThrdObj**)calloc(srv->numOfThreads, sizeof(SWorkThrdObj*)); - srv->pipe = (uv_pipe_t**)calloc(srv->numOfThreads, sizeof(uv_pipe_t*)); + srv->pThreadObj = (SWorkThrdObj**)taosMemoryCalloc(srv->numOfThreads, sizeof(SWorkThrdObj*)); + srv->pipe = (uv_pipe_t**)taosMemoryCalloc(srv->numOfThreads, sizeof(uv_pipe_t*)); srv->ip = ip; srv->port = port; uv_loop_init(srv->loop); for (int i = 0; i < srv->numOfThreads; i++) { - SWorkThrdObj* thrd = (SWorkThrdObj*)calloc(1, sizeof(SWorkThrdObj)); + SWorkThrdObj* thrd = (SWorkThrdObj*)taosMemoryCalloc(1, sizeof(SWorkThrdObj)); thrd->quit = false; srv->pThreadObj[i] = thrd; - srv->pipe[i] = (uv_pipe_t*)calloc(2, sizeof(uv_pipe_t)); + srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); int fds[2]; if (uv_socketpair(AF_UNIX, SOCK_STREAM, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) { goto End; @@ -707,7 +707,7 @@ void uvHandleQuit(SSrvMsg* msg, SWorkThrdObj* thrd) { destroyAllConn(thrd); thrd->quit = true; } - free(msg); + taosMemoryFree(msg); } void uvHandleRelease(SSrvMsg* msg, SWorkThrdObj* thrd) { // release handle to rpc init @@ -744,7 +744,7 @@ void uvHandleRegister(SSrvMsg* msg, SWorkThrdObj* thrd) { (*pTransInst->cfp)(pTransInst->parent, &(conn->regArg.msg), NULL); memset(&conn->regArg, 0, sizeof(conn->regArg)); } - free(msg); + taosMemoryFree(msg); } } void destroyWorkThrd(SWorkThrdObj* pThrd) { @@ -752,12 +752,12 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) { return; } taosThreadJoin(pThrd->thread, NULL); - free(pThrd->loop); + taosMemoryFree(pThrd->loop); transDestroyAsyncPool(pThrd->asyncPool); - free(pThrd); + taosMemoryFree(pThrd); } void sendQuitToWorkThrd(SWorkThrdObj* pThrd) { - SSrvMsg* msg = calloc(1, sizeof(SSrvMsg)); + SSrvMsg* msg = taosMemoryCalloc(1, sizeof(SSrvMsg)); msg->type = Quit; tDebug("server send quit msg to work thread"); transSendAsync(pThrd->asyncPool, &msg->q); @@ -775,16 +775,16 @@ void transCloseServer(void* arg) { uv_async_send(srv->pAcceptAsync); taosThreadJoin(srv->thread, NULL); - free(srv->pThreadObj); - free(srv->pAcceptAsync); - free(srv->loop); + taosMemoryFree(srv->pThreadObj); + taosMemoryFree(srv->pAcceptAsync); + taosMemoryFree(srv->loop); for (int i = 0; i < srv->numOfThreads; i++) { - free(srv->pipe[i]); + taosMemoryFree(srv->pipe[i]); } - free(srv->pipe); + taosMemoryFree(srv->pipe); - free(srv); + taosMemoryFree(srv); } void transRefSrvHandle(void* handle) { @@ -817,7 +817,7 @@ void transReleaseSrvHandle(void* handle) { STransMsg tmsg = {.handle = handle, .code = 0}; - SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg)); + SSrvMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSrvMsg)); srvMsg->msg = tmsg; srvMsg->type = Release; srvMsg->pConn = pConn; @@ -832,7 +832,7 @@ void transSendResponse(const STransMsg* pMsg) { SSrvConn* pConn = pMsg->handle; SWorkThrdObj* pThrd = pConn->hostThrd; - SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg)); + SSrvMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSrvMsg)); srvMsg->pConn = pConn; srvMsg->msg = *pMsg; srvMsg->type = Normal; @@ -846,7 +846,7 @@ void transRegisterMsg(const STransMsg* msg) { SSrvConn* pConn = msg->handle; SWorkThrdObj* pThrd = pConn->hostThrd; - SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg)); + SSrvMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSrvMsg)); srvMsg->pConn = pConn; srvMsg->msg = *msg; srvMsg->type = Register; diff --git a/source/libs/transport/test/rclient.c b/source/libs/transport/test/rclient.c index 4af316acae..7d3c3aa012 100644 --- a/source/libs/transport/test/rclient.c +++ b/source/libs/transport/test/rclient.c @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) { taosGetTimeOfDay(&systemTime); startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads); + SInfo *pInfo = (SInfo *)taosMemoryCalloc(1, sizeof(SInfo) * appThreads); taosThreadAttrInit(&thattr); taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); diff --git a/source/libs/transport/test/rsclient.c b/source/libs/transport/test/rsclient.c index f3be4e3452..e7fc7b45e1 100644 --- a/source/libs/transport/test/rsclient.c +++ b/source/libs/transport/test/rsclient.c @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) { taosGetTimeOfDay(&systemTime); startTime = systemTime.tv_sec*1000000 + systemTime.tv_usec; - SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo)*appThreads); + SInfo *pInfo = (SInfo *)taosMemoryCalloc(1, sizeof(SInfo)*appThreads); taosThreadAttrInit(&thattr); taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); diff --git a/source/libs/transport/test/syncClient.c b/source/libs/transport/test/syncClient.c index 14f32df0b8..27a468a86f 100644 --- a/source/libs/transport/test/syncClient.c +++ b/source/libs/transport/test/syncClient.c @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) { taosGetTimeOfDay(&systemTime); startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads); + SInfo *pInfo = (SInfo *)taosMemoryCalloc(1, sizeof(SInfo) * appThreads); taosThreadAttrInit(&thattr); taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); diff --git a/source/libs/transport/test/transportTests.cpp b/source/libs/transport/test/transportTests.cpp index 65d9302994..90122eadd1 100644 --- a/source/libs/transport/test/transportTests.cpp +++ b/source/libs/transport/test/transportTests.cpp @@ -90,7 +90,7 @@ TEST_F(QueueEnv, testPushAndPop) { assert(q->IsEmpty()); for (int i = 0; i < 100; i++) { - QueueElem *el = (QueueElem *)malloc(sizeof(QueueElem)); + QueueElem *el = (QueueElem *)taosMemoryMalloc(sizeof(QueueElem)); el->val = i; q->Push(el); } @@ -98,7 +98,7 @@ TEST_F(QueueEnv, testPushAndPop) { while (!q->IsEmpty()) { QueueElem *el = q->Pop(); assert(el->val == i++); - free(el); + taosMemoryFree(el); } assert(q->IsEmpty()); } @@ -109,7 +109,7 @@ TEST_F(QueueEnv, testRm) { assert(q->IsEmpty()); for (int i = 0; i < 100; i++) { - QueueElem *el = (QueueElem *)malloc(sizeof(QueueElem)); + QueueElem *el = (QueueElem *)taosMemoryMalloc(sizeof(QueueElem)); el->val = i; q->Push(el); set.push_back(el); @@ -117,7 +117,7 @@ TEST_F(QueueEnv, testRm) { for (int i = set.size() - 1; i >= 0; i--) { QueueElem *el = set[i]; q->RmElem(el); - free(el); + taosMemoryFree(el); } assert(q->IsEmpty()); } @@ -126,7 +126,7 @@ TEST_F(QueueEnv, testIter) { assert(q->IsEmpty()); std::vector vals; for (int i = 0; i < 100; i++) { - QueueElem *el = (QueueElem *)malloc(sizeof(QueueElem)); + QueueElem *el = (QueueElem *)taosMemoryMalloc(sizeof(QueueElem)); el->val = i; q->Push(el); vals.push_back(i); @@ -139,7 +139,7 @@ TEST_F(QueueEnv, testIter) { class TransCtxEnv : public ::testing::Test { protected: virtual void SetUp() { - ctx = (STransCtx *)calloc(1, sizeof(STransCtx)); + ctx = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); transCtxInit(ctx); // TODO } @@ -153,57 +153,57 @@ class TransCtxEnv : public ::testing::Test { TEST_F(TransCtxEnv, mergeTest) { int key = 1; { - STransCtx *src = (STransCtx *)calloc(1, sizeof(STransCtx)); + STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); transCtxInit(src); { - STransCtxVal val1 = {.val = NULL, .len = 0, .free = free}; - val1.val = malloc(12); + STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree}; + val1.val = taosMemoryMalloc(12); val1.len = 12; taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; } { - STransCtxVal val1 = {.val = NULL, .len = 0, .free = free}; - val1.val = malloc(12); + STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree}; + val1.val = taosMemoryMalloc(12); val1.len = 12; taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; } transCtxMerge(ctx, src); - free(src); + taosMemoryFree(src); } EXPECT_EQ(2, taosHashGetSize(ctx->args)); { - STransCtx *src = (STransCtx *)calloc(1, sizeof(STransCtx)); + STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); transCtxInit(src); { - STransCtxVal val1 = {.val = NULL, .len = 0, .free = free}; - val1.val = malloc(12); + STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree}; + val1.val = taosMemoryMalloc(12); val1.len = 12; taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; } { - STransCtxVal val1 = {.val = NULL, .len = 0, .free = free}; - val1.val = malloc(12); + STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree}; + val1.val = taosMemoryMalloc(12); val1.len = 12; taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; } transCtxMerge(ctx, src); - free(src); + taosMemoryFree(src); } std::string val("Hello"); EXPECT_EQ(4, taosHashGetSize(ctx->args)); { key = 1; - STransCtx *src = (STransCtx *)calloc(1, sizeof(STransCtx)); + STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); transCtxInit(src); { - STransCtxVal val1 = {.val = NULL, .len = 0, .free = free}; - val1.val = calloc(1, 11); + STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree}; + val1.val = taosMemoryCalloc(1, 11); memcpy(val1.val, val.c_str(), val.size()); val1.len = 11; @@ -211,21 +211,21 @@ TEST_F(TransCtxEnv, mergeTest) { key++; } { - STransCtxVal val1 = {.val = NULL, .len = 0, .free = free}; - val1.val = calloc(1, 11); + STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree}; + val1.val = taosMemoryCalloc(1, 11); memcpy(val1.val, val.c_str(), val.size()); val1.len = 11; taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; } transCtxMerge(ctx, src); - free(src); + taosMemoryFree(src); } EXPECT_EQ(4, taosHashGetSize(ctx->args)); char *skey = (char *)transCtxDumpVal(ctx, 1); EXPECT_EQ(0, strcmp(skey, val.c_str())); - free(skey); + taosMemoryFree(skey); skey = (char *)transCtxDumpVal(ctx, 2); EXPECT_EQ(0, strcmp(skey, val.c_str())); diff --git a/source/libs/transport/test/uv.c b/source/libs/transport/test/uv.c index 5a19b7998c..fb026ef1a6 100644 --- a/source/libs/transport/test/uv.c +++ b/source/libs/transport/test/uv.c @@ -38,7 +38,7 @@ void echo_write(uv_write_t *req, int status) { fprintf(stderr, "Write error %s\n", uv_err_name(status)); } printf("write data to client\n"); - free(req); + taosMemoryFree(req); } void echo_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { @@ -47,14 +47,14 @@ void echo_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { pConn->ref += 1; printf("read data %d\n", nread, buf->base, buf->len); if (nread > 0) { - uv_write_t *req = (uv_write_t *)malloc(sizeof(uv_write_t)); + uv_write_t *req = (uv_write_t *)taosMemoryMalloc(sizeof(uv_write_t)); // dispatch request to database other process thread // just write out uv_buf_t write_out; write_out.base = buf->base; write_out.len = nread; uv_write((uv_write_t *)req, client, &write_out, 1, echo_write); - free(buf->base); + taosMemoryFree(buf->base); return; } @@ -63,11 +63,11 @@ void echo_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { fprintf(stderr, "Read error %s\n", uv_err_name(nread)); uv_close((uv_handle_t *)client, NULL); } - free(buf->base); + taosMemoryFree(buf->base); } void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) { - buf->base = malloc(suggested_size); + buf->base = taosMemoryMalloc(suggested_size); buf->len = suggested_size; } @@ -79,10 +79,10 @@ void on_new_connection(uv_stream_t *s, int status) { SServerObj *pObj = container_of(s, SServerObj, server); printf("new_connection from client\n"); - uv_tcp_t *client = (uv_tcp_t *)malloc(sizeof(uv_tcp_t)); + uv_tcp_t *client = (uv_tcp_t *)taosMemoryMalloc(sizeof(uv_tcp_t)); uv_tcp_init(pObj->loop, client); if (uv_accept(s, (uv_stream_t *)client) == 0) { - uv_write_t *write_req = (uv_write_t *)malloc(sizeof(uv_write_t)); + uv_write_t *write_req = (uv_write_t *)taosMemoryMalloc(sizeof(uv_write_t)); uv_buf_t dummy_buf = uv_buf_init("a", 1); // despatch to worker thread pObj->workerIdx = (pObj->workerIdx + 1) % pObj->numOfThread; @@ -112,13 +112,13 @@ void child_on_new_connection(uv_stream_t *q, ssize_t nread, uv_handle_type pending = uv_pipe_pending_type(pipe); assert(pending == UV_TCP); - SConnCtx *pConn = malloc(sizeof(SConnCtx)); + SConnCtx *pConn = taosMemoryMalloc(sizeof(SConnCtx)); /* init conn timer*/ - pConn->pTimer = malloc(sizeof(uv_timer_t)); + pConn->pTimer = taosMemoryMalloc(sizeof(uv_timer_t)); uv_timer_init(pObj->loop, pConn->pTimer); - pConn->pClient = (uv_tcp_t *)malloc(sizeof(uv_tcp_t)); + pConn->pClient = (uv_tcp_t *)taosMemoryMalloc(sizeof(uv_tcp_t)); pConn->pWorkerAsync = pObj->workerAsync; // thread safty uv_tcp_init(pObj->loop, pConn->pClient); @@ -130,10 +130,10 @@ void child_on_new_connection(uv_stream_t *q, ssize_t nread, uv_read_start((uv_stream_t *)(pConn->pClient), alloc_buffer, echo_read); } else { uv_timer_stop(pConn->pTimer); - free(pConn->pTimer); + taosMemoryFree(pConn->pTimer); uv_close((uv_handle_t *)pConn->pClient, NULL); - free(pConn->pClient); - free(pConn); + taosMemoryFree(pConn->pClient); + taosMemoryFree(pConn); } } @@ -144,13 +144,13 @@ static void workerAsyncCallback(uv_async_t *handle) { void *worker_thread(void *arg) { SThreadObj *pObj = (SThreadObj *)arg; int fd = pObj->fd; - pObj->loop = (uv_loop_t *)malloc(sizeof(uv_loop_t)); + pObj->loop = (uv_loop_t *)taosMemoryMalloc(sizeof(uv_loop_t)); uv_loop_init(pObj->loop); uv_pipe_init(pObj->loop, pObj->pipe, 1); uv_pipe_open(pObj->pipe, fd); - pObj->workerAsync = malloc(sizeof(uv_async_t)); + pObj->workerAsync = taosMemoryMalloc(sizeof(uv_async_t)); uv_async_init(pObj->loop, pObj->workerAsync, workerAsyncCallback); uv_read_start((uv_stream_t *)pObj->pipe, alloc_buffer, child_on_new_connection); @@ -159,19 +159,19 @@ void *worker_thread(void *arg) { } int main() { - SServerObj *server = calloc(1, sizeof(SServerObj)); - server->loop = (uv_loop_t *)malloc(sizeof(uv_loop_t)); + SServerObj *server = taosMemoryCalloc(1, sizeof(SServerObj)); + server->loop = (uv_loop_t *)taosMemoryMalloc(sizeof(uv_loop_t)); server->numOfThread = NUM_OF_THREAD; server->workerIdx = 0; server->pThreadObj = - (SThreadObj **)calloc(server->numOfThread, sizeof(SThreadObj *)); - server->pipe = (uv_pipe_t **)calloc(server->numOfThread, sizeof(uv_pipe_t *)); + (SThreadObj **)taosMemoryCalloc(server->numOfThread, sizeof(SThreadObj *)); + server->pipe = (uv_pipe_t **)taosMemoryCalloc(server->numOfThread, sizeof(uv_pipe_t *)); uv_loop_init(server->loop); for (int i = 0; i < server->numOfThread; i++) { - server->pThreadObj[i] = (SThreadObj *)calloc(1, sizeof(SThreadObj)); - server->pipe[i] = (uv_pipe_t *)calloc(2, sizeof(uv_pipe_t)); + server->pThreadObj[i] = (SThreadObj *)taosMemoryCalloc(1, sizeof(SThreadObj)); + server->pipe[i] = (uv_pipe_t *)taosMemoryCalloc(2, sizeof(uv_pipe_t)); int fds[2]; if (uv_socketpair(AF_UNIX, SOCK_STREAM, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) { diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 70ec7e0655..cbe7cb81db 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -74,7 +74,7 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) { uint64_t magic = WAL_MAGIC; - char* buf = malloc(readSize + 5); + char* buf = taosMemoryMalloc(readSize + 5); if (buf == NULL) { taosCloseFile(&pFile); terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; @@ -83,7 +83,7 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) { taosLSeekFile(pFile, -readSize, SEEK_END); if (readSize != taosReadFile(pFile, buf, readSize)) { - free(buf); + taosMemoryFree(buf); taosCloseFile(&pFile); terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -104,7 +104,7 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) { SWalHead *logContent = (SWalHead*)found; if (walValidHeadCksum(logContent) != 0 || walValidBodyCksum(logContent) != 0) { // file has to be deleted - free(buf); + taosMemoryFree(buf); taosCloseFile(&pFile); terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; @@ -215,7 +215,7 @@ int walRollFileInfo(SWal* pWal) { } // TODO: change to emplace back - SWalFileInfo* pNewInfo = malloc(sizeof(SWalFileInfo)); + SWalFileInfo* pNewInfo = taosMemoryMalloc(sizeof(SWalFileInfo)); if (pNewInfo == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; return -1; @@ -226,7 +226,7 @@ int walRollFileInfo(SWal* pWal) { pNewInfo->closeTs = -1; pNewInfo->fileSize = 0; taosArrayPush(pArray, pNewInfo); - free(pNewInfo); + taosMemoryFree(pNewInfo); return 0; } @@ -378,7 +378,7 @@ int walSaveMeta(SWal* pWal) { walBuildMetaName(pWal, metaVer, fnameStr); taosRemoveFile(fnameStr); } - free(serialized); + taosMemoryFree(serialized); return 0; } @@ -395,7 +395,7 @@ int walLoadMeta(SWal* pWal) { int64_t file_size = 0; taosStatFile(fnameStr, &file_size, NULL); int size = (int)file_size; - char* buf = malloc(size + 5); + char* buf = taosMemoryMalloc(size + 5); if (buf == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; return -1; @@ -409,12 +409,12 @@ int walLoadMeta(SWal* pWal) { if (taosReadFile(pFile, buf, size) != size) { terrno = TAOS_SYSTEM_ERROR(errno); taosCloseFile(&pFile); - free(buf); + taosMemoryFree(buf); return -1; } // load into fileInfoSet int code = walMetaDeserialize(pWal, buf); taosCloseFile(&pFile); - free(buf); + taosMemoryFree(buf); return code; } diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 2da8f4f8af..cf40c998de 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -63,7 +63,7 @@ void walCleanUp() { } SWal *walOpen(const char *path, SWalCfg *pCfg) { - SWal *pWal = malloc(sizeof(SWal)); + SWal *pWal = taosMemoryMalloc(sizeof(SWal)); if (pWal == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return NULL; @@ -88,7 +88,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { pWal->fileInfoSet = taosArrayInit(8, sizeof(SWalFileInfo)); if (pWal->fileInfoSet == NULL) { wError("vgId:%d, path:%s, failed to init taosArray %s", pWal->cfg.vgId, pWal->path, strerror(errno)); - free(pWal); + taosMemoryFree(pWal); return NULL; } @@ -103,7 +103,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { if (taosThreadMutexInit(&pWal->mutex, NULL) < 0) { taosArrayDestroy(pWal->fileInfoSet); - free(pWal); + taosMemoryFree(pWal); return NULL; } @@ -111,7 +111,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { if (pWal->refId < 0) { taosThreadMutexDestroy(&pWal->mutex); taosArrayDestroy(pWal->fileInfoSet); - free(pWal); + taosMemoryFree(pWal); return NULL; } @@ -121,7 +121,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { taosRemoveRef(tsWal.refSetId, pWal->refId); taosThreadMutexDestroy(&pWal->mutex); taosArrayDestroy(pWal->fileInfoSet); - free(pWal); + taosMemoryFree(pWal); return NULL; } @@ -174,7 +174,7 @@ static void walFreeObj(void *wal) { wDebug("vgId:%d, wal:%p is freed", pWal->cfg.vgId, pWal); taosThreadMutexDestroy(&pWal->mutex); - tfree(pWal); + taosMemoryFreeClear(pWal); } static bool walNeedFsync(SWal *pWal) { diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 8d3acef9e7..e15c162048 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -17,7 +17,7 @@ #include "taoserror.h" SWalReadHandle *walOpenReadHandle(SWal *pWal) { - SWalReadHandle *pRead = malloc(sizeof(SWalReadHandle)); + SWalReadHandle *pRead = taosMemoryMalloc(sizeof(SWalReadHandle)); if (pRead == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -30,10 +30,10 @@ SWalReadHandle *walOpenReadHandle(SWal *pWal) { pRead->curFileFirstVer = -1; pRead->capacity = 0; pRead->status = 0; - pRead->pHead = malloc(sizeof(SWalHead)); + pRead->pHead = taosMemoryMalloc(sizeof(SWalHead)); if (pRead->pHead == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; - free(pRead); + taosMemoryFree(pRead); return NULL; } return pRead; @@ -42,8 +42,8 @@ SWalReadHandle *walOpenReadHandle(SWal *pWal) { void walCloseReadHandle(SWalReadHandle *pRead) { taosCloseFile(&pRead->pReadIdxTFile); taosCloseFile(&pRead->pReadLogTFile); - tfree(pRead->pHead); - free(pRead); + taosMemoryFreeClear(pRead->pHead); + taosMemoryFree(pRead); } int32_t walRegisterRead(SWalReadHandle *pRead, int64_t ver) { return 0; } @@ -156,7 +156,7 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) { return -1; } if (pRead->capacity < pRead->pHead->head.len) { - void *ptr = realloc(pRead->pHead, sizeof(SWalHead) + pRead->pHead->head.len); + void *ptr = taosMemoryRealloc(pRead->pHead, sizeof(SWalHead) + pRead->pHead->head.len); if (ptr == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; return -1; @@ -195,7 +195,7 @@ int32_t walRead(SWal *pWal, SWalHead **ppHead, int64_t ver) { return code; } if (*ppHead == NULL) { - void *ptr = realloc(*ppHead, sizeof(SWalHead)); + void *ptr = taosMemoryRealloc(*ppHead, sizeof(SWalHead)); if (ptr == NULL) { return -1; } @@ -208,9 +208,9 @@ int32_t walRead(SWal *pWal, SWalHead **ppHead, int64_t ver) { if (walValidHeadCksum(*ppHead) != 0) { return -1; } - void *ptr = realloc(*ppHead, sizeof(SWalHead) + (*ppHead)->head.len); + void *ptr = taosMemoryRealloc(*ppHead, sizeof(SWalHead) + (*ppHead)->head.len); if (ptr == NULL) { - free(*ppHead); + taosMemoryFree(*ppHead); *ppHead = NULL; return -1; } diff --git a/source/libs/wal/test/walMetaTest.cpp b/source/libs/wal/test/walMetaTest.cpp index 69ae83154a..b1de3a1dce 100644 --- a/source/libs/wal/test/walMetaTest.cpp +++ b/source/libs/wal/test/walMetaTest.cpp @@ -19,7 +19,7 @@ class WalCleanEnv : public ::testing::Test { void SetUp() override { taosRemoveDir(pathName); - SWalCfg* pCfg = (SWalCfg*)malloc(sizeof(SWalCfg)); + SWalCfg* pCfg = (SWalCfg*)taosMemoryMalloc(sizeof(SWalCfg)); memset(pCfg, 0, sizeof(SWalCfg)); pCfg->rollPeriod = -1; pCfg->segSize = -1; @@ -27,7 +27,7 @@ class WalCleanEnv : public ::testing::Test { pCfg->retentionSize = 0; pCfg->level = TAOS_WAL_FSYNC; pWal = walOpen(pathName, pCfg); - free(pCfg); + taosMemoryFree(pCfg); ASSERT(pWal != NULL); } @@ -51,13 +51,13 @@ class WalCleanDeleteEnv : public ::testing::Test { void SetUp() override { taosRemoveDir(pathName); - SWalCfg* pCfg = (SWalCfg*)malloc(sizeof(SWalCfg)); + SWalCfg* pCfg = (SWalCfg*)taosMemoryMalloc(sizeof(SWalCfg)); memset(pCfg, 0, sizeof(SWalCfg)); pCfg->retentionPeriod = 0; pCfg->retentionSize = 0; pCfg->level = TAOS_WAL_FSYNC; pWal = walOpen(pathName, pCfg); - free(pCfg); + taosMemoryFree(pCfg); ASSERT(pWal != NULL); } @@ -86,7 +86,7 @@ class WalKeepEnv : public ::testing::Test { } void SetUp() override { - SWalCfg* pCfg = (SWalCfg*)malloc(sizeof(SWalCfg)); + SWalCfg* pCfg = (SWalCfg*)taosMemoryMalloc(sizeof(SWalCfg)); memset(pCfg, 0, sizeof(SWalCfg)); pCfg->rollPeriod = -1; pCfg->segSize = -1; @@ -94,7 +94,7 @@ class WalKeepEnv : public ::testing::Test { pCfg->retentionSize = 0; pCfg->level = TAOS_WAL_FSYNC; pWal = walOpen(pathName, pCfg); - free(pCfg); + taosMemoryFree(pCfg); ASSERT(pWal != NULL); } @@ -172,7 +172,7 @@ TEST_F(WalCleanEnv, serialize) { ASSERT(code == 0); char* ss = walMetaSerialize(pWal); printf("%s\n", ss); - free(ss); + taosMemoryFree(ss); code = walSaveMeta(pWal); ASSERT(code == 0); } @@ -216,8 +216,8 @@ TEST_F(WalKeepEnv, readOldMeta) { for (int i = 0; i < len; i++) { EXPECT_EQ(oldss[i], newss[i]); } - free(oldss); - free(newss); + taosMemoryFree(oldss); + taosMemoryFree(newss); } TEST_F(WalCleanEnv, write) { diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 4dece8abef..ed93708c07 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -268,7 +268,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { autoDelFileListAdd(path); } - TdFilePtr pFile = (TdFilePtr)malloc(sizeof(TdFile)); + TdFilePtr pFile = (TdFilePtr)taosMemoryMalloc(sizeof(TdFile)); if (pFile == NULL) { if (fd >= 0) close(fd); if (fp != NULL) fclose(fp); @@ -312,7 +312,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) { taosThreadRwlockUnlock(&((*ppFile)->rwlock)); taosThreadRwlockDestroy(&((*ppFile)->rwlock)); #endif - free(*ppFile); + taosMemoryFree(*ppFile); *ppFile = NULL; return 0; #endif diff --git a/source/os/src/osLocale.c b/source/os/src/osLocale.c index 5f12f9cd3d..2df61c08d4 100644 --- a/source/os/src/osLocale.c +++ b/source/os/src/osLocale.c @@ -134,7 +134,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) { char *revisedCharset = taosCharsetReplace(str); tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN); - free(revisedCharset); + taosMemoryFree(revisedCharset); // printf("charset not configured, set to system default:%s", outCharset); } else { strcpy(outCharset, "UTF-8"); @@ -179,7 +179,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) { char *revisedCharset = taosCharsetReplace(str); tstrncpy(outCharset, revisedCharset, TD_LOCALE_LEN); - free(revisedCharset); + taosMemoryFree(revisedCharset); // printf("charset not configured, set to system default:%s", outCharset); } else { strcpy(outCharset, "UTF-8"); diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c new file mode 100644 index 0000000000..d044de79db --- /dev/null +++ b/source/os/src/osMemory.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define ALLOW_FORBID_FUNC +#include "os.h" + +#define USE_TD_MEMORY + +#define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S') + +#define TEST_SIZE 4 + +typedef struct TdMemoryInfo +{ + int32_t symbol; + char **stackTrace; + int32_t stackTraceDepth; + int32_t memorySize; +} *TdMemoryInfoPtr , TdMemoryInfo; + +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + +#else + +#include +#define STACKCALL __attribute__((regparm(1), noinline)) +void **STACKCALL taosGetEBP(void) { + void **ebp = NULL; + __asm__ __volatile__("mov %%rbp, %0;\n\t" + : "=m"(ebp) /* output */ + : /* input */ + : "memory"); /* not affect register */ + return (void **)(*ebp); +} +int32_t taosBackTrace(void **buffer, int32_t size) { + int32_t frame = 0; + void **ebp; + void **ret = NULL; + unsigned long long func_frame_distance = 0; + if (buffer != NULL && size > 0) { + ebp = taosGetEBP(); + func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp; + while (ebp && frame < size && (func_frame_distance < (1ULL << 24)) // assume function ebp more than 16M + && (func_frame_distance > 0)) { + ret = ebp + 1; + buffer[frame++] = *ret; + ebp = (void **)(*ebp); + func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp; + } + } + return frame; +} +#endif + +char **taosBackTraceSymbols(int32_t *size) { + void *buffer[20] = {NULL}; + *size = taosBackTrace(buffer, 10); + return backtrace_symbols(buffer, *size); +} + +void *taosMemoryMalloc(int32_t size) { + if (tmp == NULL) return NULL; + + void *tmp = malloc(size + sizeof(TdMemoryInfo)); + TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)tmp; + pTdMemoryInfo->memorySize = size; + pTdMemoryInfo->symbol = TD_MEMORY_SYMBOL; + pTdMemoryInfo->stackTrace = taosBackTraceSymbols(&pTdMemoryInfo->stackTraceDepth); + + return (char*)tmp + sizeof(TdMemoryInfo); +} + +void *taosMemoryCalloc(int32_t num, int32_t size) { + int32_t memorySize = num * size; + char *tmp = calloc(memorySize + sizeof(TdMemoryInfo), 1); + if (tmp == NULL) return NULL; + + TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)tmp; + pTdMemoryInfo->memorySize = memorySize; + pTdMemoryInfo->symbol = TD_MEMORY_SYMBOL; + pTdMemoryInfo->stackTrace = taosBackTraceSymbols(&pTdMemoryInfo->stackTraceDepth); + + return (char*)tmp + sizeof(TdMemoryInfo); +} + +void *taosMemoryRealloc(void *ptr, int32_t size) { + if (ptr == NULL) return taosMemoryMalloc(size); + + TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); + assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); + + TdMemoryInfo tdMemoryInfo; + memcpy(&tdMemoryInfo, pTdMemoryInfo, sizeof(TdMemoryInfo)); + + void *tmp = realloc(pTdMemoryInfo, size + sizeof(TdMemoryInfo)); + if (tmp == NULL) return NULL; + + memcpy(tmp, &tdMemoryInfo, sizeof(TdMemoryInfo)); + ((TdMemoryInfoPtr)tmp)->memorySize = size; + + return (char*)tmp + sizeof(TdMemoryInfo); +} + +void taosMemoryFree(const void *ptr) { + if (ptr == NULL) return; + + TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); + if(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL) { + if(pTdMemoryInfo->stackTrace != NULL) free(pTdMemoryInfo->stackTrace); + memset(pTdMemoryInfo, 0, sizeof(TdMemoryInfo)); + free(pTdMemoryInfo); + } else { + free((void*)ptr); + } +} + +int32_t taosMemorySize(void *ptr) { + if (ptr == NULL) return 0; + + TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); + assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); + + return pTdMemoryInfo->memorySize; +} \ No newline at end of file diff --git a/source/os/src/osSemaphore.c b/source/os/src/osSemaphore.c index b41ef898d4..1297fdbc27 100644 --- a/source/os/src/osSemaphore.c +++ b/source/os/src/osSemaphore.c @@ -143,7 +143,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) { fprintf(stderr, "==%s[%d]%s():[%p]==already initialized\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem); abort(); } - struct tsem_s *p = (struct tsem_s *)calloc(1, sizeof(*p)); + struct tsem_s *p = (struct tsem_s *)taosMemoryCalloc(1, sizeof(*p)); if (!p) { fprintf(stderr, "==%s[%d]%s():[%p]==out of memory\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem); abort(); @@ -331,7 +331,7 @@ int tsem_destroy(tsem_t *sem) { #endif // SEM_USE_PTHREAD p->valid = 0; - free(p); + taosMemoryFree(p); *sem = NULL; return 0; diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index f693ad74de..b130689d4b 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -117,7 +117,7 @@ int32_t taosCloseSocket(TdSocketPtr *ppSocket) { } code = taosCloseSocketNoCheck1((*ppSocket)->fd); (*ppSocket)->fd = -1; - free(*ppSocket); + taosMemoryFree(*ppSocket); return code; } int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer) { @@ -127,7 +127,7 @@ int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer) { } code = taosCloseSocketNoCheck1((*ppSocketServer)->fd); (*ppSocketServer)->fd = -1; - free(*ppSocketServer); + taosMemoryFree(*ppSocketServer); return code; } @@ -440,7 +440,7 @@ TdSocketPtr taosOpenUdpSocket(uint32_t ip, uint16_t port) { return NULL; } - TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); if (pSocket == NULL) { taosCloseSocketNoCheck1(fd); return NULL; @@ -484,7 +484,7 @@ TdSocketPtr taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t return NULL; } - TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); if (pSocket == NULL) { taosCloseSocketNoCheck1(fd); return NULL; @@ -654,7 +654,7 @@ TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { return NULL; } - TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); if (pSocket == NULL) { taosCloseSocketNoCheck1(fd); return NULL; @@ -703,7 +703,7 @@ TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, struct s return NULL; } - TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); if (pSocket == NULL) { taosCloseSocketNoCheck1(fd); return NULL; @@ -901,7 +901,7 @@ TdEpollPtr taosCreateEpoll(int32_t size) { return NULL; } - TdEpollPtr pEpoll = (TdEpollPtr)malloc(sizeof(TdEpoll)); + TdEpollPtr pEpoll = (TdEpollPtr)taosMemoryMalloc(sizeof(TdEpoll)); if (pEpoll == NULL) { taosCloseSocketNoCheck1(fd); return NULL; @@ -939,6 +939,6 @@ int32_t taosCloseEpoll(TdEpollPtr *ppEpoll) { } code = taosCloseSocketNoCheck1((*ppEpoll)->fd); (*ppEpoll)->fd = -1; - free(*ppEpoll); + taosMemoryFree(*ppEpoll); return code; } diff --git a/source/os/src/osString.c b/source/os/src/osString.c index d3d1ab5dda..5adb564e52 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -15,7 +15,6 @@ #define ALLOW_FORBID_FUNC #define _DEFAULT_SOURCE -#include #include "os.h" #ifndef DISALLOW_NCHAR_WITHOUT_ICONV @@ -50,8 +49,8 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) { #if 0 int32_t ucs4_max_len = bytes + 4; - char *f1_mbs = calloc(bytes, 1); - char *f2_mbs = calloc(bytes, 1); + char *f1_mbs = taosMemoryCalloc(bytes, 1); + char *f2_mbs = taosMemoryCalloc(bytes, 1); if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) { return -1; } @@ -59,15 +58,15 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) { return -1; } int32_t ret = strcmp(f1_mbs, f2_mbs); - free(f1_mbs); - free(f2_mbs); + taosMemoryFree(f1_mbs); + taosMemoryFree(f2_mbs); return ret; #endif } TdUcs4* tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) { - assert(malloc_usable_size(target_ucs4)>=len_ucs4*sizeof(TdUcs4)); + assert(taosMemorySize(target_ucs4)>=len_ucs4*sizeof(TdUcs4)); return memcpy(target_ucs4, source_ucs4, len_ucs4*sizeof(TdUcs4)); } diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 9bff760509..eb5712d2e5 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -145,7 +145,7 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { sscanf(line, "%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle); - if (line != NULL) tfree(line); + if (line != NULL) taosMemoryFreeClear(line); taosCloseFile(&pFile); return 0; } @@ -174,7 +174,7 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { } } - if (line != NULL) tfree(line); + if (line != NULL) taosMemoryFreeClear(line); taosCloseFile(&pFile); return 0; } @@ -268,7 +268,7 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) { } } - if (line != NULL) free(line); + if (line != NULL) taosMemoryFree(line); taosCloseFile(&pFile); return code; #else @@ -293,7 +293,7 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) { } } - if (line != NULL) free(line); + if (line != NULL) taosMemoryFree(line); taosCloseFile(&pFile); return code; #endif @@ -324,7 +324,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { } } - if (line != NULL) free(line); + if (line != NULL) taosMemoryFree(line); taosCloseFile(&pFile); return code; @@ -351,7 +351,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { } } - if (line != NULL) free(line); + if (line != NULL) taosMemoryFree(line); taosCloseFile(&pFile); return code; @@ -486,7 +486,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) { char tmp[10]; sscanf(line, "%s %" PRId64, tmp, usedKB); - if (line != NULL) tfree(line); + if (line != NULL) taosMemoryFreeClear(line); taosCloseFile(&pFile); return 0; #endif @@ -606,7 +606,7 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int if (readIndex >= 4) break; } - if (line != NULL) tfree(line); + if (line != NULL) taosMemoryFreeClear(line); taosCloseFile(&pFile); if (readIndex < 4) { @@ -665,7 +665,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { *transmit_bytes = o_tbytes; } - if (line != NULL) tfree(line); + if (line != NULL) taosMemoryFreeClear(line); taosCloseFile(&pFile); return 0; diff --git a/source/util/src/talgo.c b/source/util/src/talgo.c index cb0a2d25a9..48a0f327c4 100644 --- a/source/util/src/talgo.c +++ b/source/util/src/talgo.c @@ -153,9 +153,9 @@ static void tqsortImpl(void *src, int32_t start, int32_t end, int64_t size, cons } void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn) { - char *buf = calloc(1, size); // prepare the swap buffer + char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer tqsortImpl(src, 0, (int32_t)numOfElem - 1, (int32_t)size, param, comparFn, buf); - tfree(buf); + taosMemoryFreeClear(buf); } void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t compar, int32_t flags) { @@ -239,7 +239,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const child = 2 * parent + 1; if (swap == NULL) { - buf = calloc(1, size); + buf = taosMemoryCalloc(1, size); if (buf == NULL) { return; } @@ -288,7 +288,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const } if (swap == NULL) { - tfree(buf); + taosMemoryFreeClear(buf); } } } @@ -304,13 +304,13 @@ void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, } /* - char *buf = calloc(1, size); + char *buf = taosMemoryCalloc(1, size); for (i = len - 1; i > 0; i--) { doswap(elePtrAt(base, size, 0), elePtrAt(base, size, i)); taosheapadjust(base, size, 0, i - 1, parcompar, compar, parswap, swap, maxroot); } - tfree(buf); + taosMemoryFreeClear(buf); */ } diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c index 1127a21255..a74b26a386 100644 --- a/source/util/src/tarray.c +++ b/source/util/src/tarray.c @@ -23,15 +23,15 @@ SArray* taosArrayInit(size_t size, size_t elemSize) { size = TARRAY_MIN_SIZE; } - SArray* pArray = malloc(sizeof(SArray)); + SArray* pArray = taosMemoryMalloc(sizeof(SArray)); if (pArray == NULL) { return NULL; } pArray->size = 0; - pArray->pData = calloc(size, elemSize); + pArray->pData = taosMemoryCalloc(size, elemSize); if (pArray->pData == NULL) { - free(pArray); + taosMemoryFree(pArray); return NULL; } @@ -46,7 +46,7 @@ static int32_t taosArrayResize(SArray* pArray) { size_t size = pArray->capacity; size = (size << 1u); - void* tmp = realloc(pArray->pData, size * pArray->elemSize); + void* tmp = taosMemoryRealloc(pArray->pData, size * pArray->elemSize); if (tmp == NULL) { // reallocate failed, the original buffer remains return -1; } @@ -64,7 +64,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t newCap) { tsize = (tsize << 1u); } - pArray->pData = realloc(pArray->pData, tsize * pArray->elemSize); + pArray->pData = taosMemoryRealloc(pArray->pData, tsize * pArray->elemSize); if (pArray->pData == NULL) { return -1; } @@ -305,8 +305,8 @@ void taosArrayClear(SArray* pArray) { void* taosArrayDestroy(SArray* pArray) { if (pArray) { - free(pArray->pData); - free(pArray); + taosMemoryFree(pArray->pData); + taosMemoryFree(pArray); } return NULL; diff --git a/source/util/src/tbase64.c b/source/util/src/tbase64.c index c5119e8b2d..a2f4ddbc51 100644 --- a/source/util/src/tbase64.c +++ b/source/util/src/tbase64.c @@ -20,7 +20,7 @@ static char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01 char *base64_encode(const uint8_t *value, int32_t vlen) { uint8_t oval = 0; - char *result = (char *)malloc((size_t)(vlen * 4) / 3 + 10); + char *result = (char *)taosMemoryMalloc((size_t)(vlen * 4) / 3 + 10); char *out = result; while (vlen >= 3) { *out++ = basis_64[value[0] >> 2]; @@ -53,7 +53,7 @@ static signed char index_64[128] = { uint8_t *base64_decode(const char *value, int32_t inlen, int32_t *outlen) { int32_t c1, c2, c3, c4; - uint8_t *result = (uint8_t *)malloc((size_t)(inlen * 3) / 4 + 1); + uint8_t *result = (uint8_t *)taosMemoryMalloc((size_t)(inlen * 3) / 4 + 1); uint8_t *out = result; *outlen = 0; @@ -93,7 +93,7 @@ uint8_t *base64_decode(const char *value, int32_t inlen, int32_t *outlen) { } base64_decode_error: - free(result); + taosMemoryFree(result); result = 0; *outlen = 0; diff --git a/source/util/src/tbuffer.c b/source/util/src/tbuffer.c index dc8c4b70c5..8552ccac2c 100644 --- a/source/util/src/tbuffer.c +++ b/source/util/src/tbuffer.c @@ -213,7 +213,7 @@ double tbufReadDouble(SBufferReader* buf) { // writer functions void tbufCloseWriter(SBufferWriter* buf) { - tfree(buf->data); + taosMemoryFreeClear(buf->data); // (*buf->allocator)( buf->data, 0 ); // potential memory leak. buf->data = NULL; buf->pos = 0; diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c index cf5b623678..c4e85a425e 100644 --- a/source/util/src/tcache.c +++ b/source/util/src/tcache.c @@ -221,7 +221,7 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheNode * pCacheObj->freeFp(pNode->data); } - free(pNode); + taosMemoryFree(pNode); } static FORCE_INLINE STrashElem *doRemoveElemInTrashcan(SCacheObj *pCacheObj, STrashElem *pElem) { @@ -255,8 +255,8 @@ static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj *pCacheObj, STrashElem pCacheObj->freeFp(pElem->pData->data); } - free(pElem->pData); - free(pElem); + taosMemoryFree(pElem->pData); + taosMemoryFree(pElem); } static void pushfrontNodeInEntryList(SCacheEntry *pEntry, SCacheNode *pNode) { @@ -358,7 +358,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext return NULL; } - SCacheObj *pCacheObj = (SCacheObj *)calloc(1, sizeof(SCacheObj)); + SCacheObj *pCacheObj = (SCacheObj *)taosMemoryCalloc(1, sizeof(SCacheObj)); if (pCacheObj == NULL) { uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; @@ -366,9 +366,9 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext // TODO add the auto extend procedure pCacheObj->capacity = 4096; - pCacheObj->pEntryList = calloc(pCacheObj->capacity, sizeof(SCacheEntry)); + pCacheObj->pEntryList = taosMemoryCalloc(pCacheObj->capacity, sizeof(SCacheEntry)); if (pCacheObj->pEntryList == NULL) { - free(pCacheObj); + taosMemoryFree(pCacheObj); uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; } @@ -381,8 +381,8 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext pCacheObj->extendLifespan = extendLifespan; // the TTL after the last access if (__trashcan_lock_init(pCacheObj) != 0) { - tfree(pCacheObj->pEntryList); - free(pCacheObj); + taosMemoryFreeClear(pCacheObj->pEntryList); + taosMemoryFree(pCacheObj); uError("failed to init lock, reason:%s", strerror(errno)); return NULL; @@ -432,7 +432,7 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v } atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size); - tfree(pNode); + taosMemoryFreeClear(pNode); } else { taosAddToTrashcan(pCacheObj, pNode); uDebug("cache:%s, key:%p, %p exist in cache, updated old:%p", pCacheObj->name, key, pNode1->data, pNode->data); @@ -625,7 +625,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { pCacheObj->freeFp(pNode->data); } - free(pNode); + taosMemoryFree(pNode); } } @@ -703,7 +703,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { SCacheNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *pData, size_t size, uint64_t duration) { size_t sizeInBytes = size + sizeof(SCacheNode) + keyLen; - SCacheNode *pNewNode = calloc(1, sizeInBytes); + SCacheNode *pNewNode = taosMemoryCalloc(1, sizeInBytes); if (pNewNode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; uError("failed to allocate memory, reason:%s", strerror(errno)); @@ -735,7 +735,7 @@ void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheNode *pNode) { } __trashcan_wr_lock(pCacheObj); - STrashElem *pElem = calloc(1, sizeof(STrashElem)); + STrashElem *pElem = taosMemoryCalloc(1, sizeof(STrashElem)); pElem->pData = pNode; pElem->prev = NULL; pElem->next = NULL; @@ -802,9 +802,9 @@ void doCleanupDataCache(SCacheObj *pCacheObj) { __trashcan_lock_destroy(pCacheObj); - tfree(pCacheObj->pEntryList); - tfree(pCacheObj->name); - free(pCacheObj); + taosMemoryFreeClear(pCacheObj->pEntryList); + taosMemoryFreeClear(pCacheObj->name); + taosMemoryFree(pCacheObj); } static void doCacheRefresh(SCacheObj *pCacheObj, int64_t time, __cache_trav_fn_t fp, void *param1) { @@ -918,7 +918,7 @@ size_t taosCacheGetNumOfObj(const SCacheObj* pCacheObj) { SCacheIter* taosCacheCreateIter(const SCacheObj* pCacheObj) { ASSERT(pCacheObj != NULL); - SCacheIter* pIter = calloc(1, sizeof(SCacheIter)); + SCacheIter* pIter = taosMemoryCalloc(1, sizeof(SCacheIter)); pIter->pCacheObj = (SCacheObj*) pCacheObj; pIter->entryIndex = -1; pIter->index = -1; @@ -955,7 +955,7 @@ bool taosCacheIterNext(SCacheIter* pIter) { } if (pIter->numOfObj < pEntry->num) { - char *tmp = realloc(pIter->pCurrent, pEntry->num * POINTER_BYTES); + char *tmp = taosMemoryRealloc(pIter->pCurrent, pEntry->num * POINTER_BYTES); if (tmp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; taosRUnLockLatch(&pEntry->latch); @@ -1001,6 +1001,6 @@ void* taosCacheIterGetKey(const SCacheIter* pIter, size_t* len) { } void taosCacheDestroyIter(SCacheIter* pIter) { - tfree(pIter->pCurrent); - tfree(pIter); + taosMemoryFreeClear(pIter->pCurrent); + taosMemoryFreeClear(pIter); } \ No newline at end of file diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index ff7d2cf733..c98f6eb9be 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -355,12 +355,12 @@ int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight) { int32_t compareStrRegexComp(const void *pLeft, const void *pRight) { size_t sz = varDataLen(pRight); - char *pattern = malloc(sz + 1); + char *pattern = taosMemoryMalloc(sz + 1); memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); pattern[sz] = 0; sz = varDataLen(pLeft); - char *str = malloc(sz + 1); + char *str = taosMemoryMalloc(sz + 1); memcpy(str, varDataVal(pLeft), sz); str[sz] = 0; @@ -373,8 +373,8 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight) { regerror(errCode, ®ex, msgbuf, sizeof(msgbuf)); uError("Failed to compile regex pattern %s. reason %s", pattern, msgbuf); regfree(®ex); - free(str); - free(pattern); + taosMemoryFree(str); + taosMemoryFree(pattern); return 1; } @@ -385,8 +385,8 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight) { } int32_t result = (errCode == 0) ? 0 : 1; regfree(®ex); - free(str); - free(pattern); + taosMemoryFree(str); + taosMemoryFree(pattern); return result; } @@ -401,17 +401,17 @@ int32_t compareStrPatternMatch(const void *pLeft, const void *pRight) { SPatternCompareInfo pInfo = {'%', '_'}; assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN); - char *pattern = calloc(varDataLen(pRight) + 1, sizeof(char)); + char *pattern = taosMemoryCalloc(varDataLen(pRight) + 1, sizeof(char)); memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); size_t sz = varDataLen(pLeft); - char *buf = malloc(sz + 1); + char *buf = taosMemoryMalloc(sz + 1); memcpy(buf, varDataVal(pLeft), sz); buf[sz] = 0; int32_t ret = patternMatch(pattern, buf, sz, &pInfo); - free(buf); - free(pattern); + taosMemoryFree(buf); + taosMemoryFree(pattern); return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; } @@ -424,11 +424,11 @@ int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight) { assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE); - char *pattern = calloc(varDataLen(pRight) + TSDB_NCHAR_SIZE, 1); + char *pattern = taosMemoryCalloc(varDataLen(pRight) + TSDB_NCHAR_SIZE, 1); memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); int32_t ret = WCSPatternMatch((TdUcs4*)pattern, (TdUcs4*)varDataVal(pLeft), varDataLen(pLeft) / TSDB_NCHAR_SIZE, &pInfo); - free(pattern); + taosMemoryFree(pattern); return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 404c9c8f71..96bb638b95 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -29,7 +29,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url); int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype); SConfig *cfgInit() { - SConfig *pCfg = calloc(1, sizeof(SConfig)); + SConfig *pCfg = taosMemoryCalloc(1, sizeof(SConfig)); if (pCfg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -37,7 +37,7 @@ SConfig *cfgInit() { pCfg->array = taosArrayInit(32, sizeof(SConfigItem)); if (pCfg->array == NULL) { - free(pCfg); + taosMemoryFree(pCfg); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -75,7 +75,7 @@ int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs) { static void cfgFreeItem(SConfigItem *pItem) { if (pItem->dtype == CFG_DTYPE_STRING || pItem->dtype == CFG_DTYPE_DIR || pItem->dtype == CFG_DTYPE_LOCALE || pItem->dtype == CFG_DTYPE_CHARSET || pItem->dtype == CFG_DTYPE_TIMEZONE) { - tfree(pItem->str); + taosMemoryFreeClear(pItem->str); } if (pItem->array) { taosArrayDestroy(pItem->array); @@ -89,10 +89,10 @@ void cfgCleanup(SConfig *pCfg) { for (int32_t i = 0; i < size; ++i) { SConfigItem *pItem = taosArrayGet(pCfg->array, i); cfgFreeItem(pItem); - tfree(pItem->name); + taosMemoryFreeClear(pItem->name); } taosArrayDestroy(pCfg->array); - free(pCfg); + taosMemoryFree(pCfg); } } @@ -145,7 +145,7 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { return -1; } - tfree(pItem->str); + taosMemoryFreeClear(pItem->str); pItem->str = strdup(fullDir); if (pItem->str == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -224,7 +224,7 @@ static int32_t cfgSetString(SConfigItem *pItem, const char *value, ECfgSrcType s return -1; } - free(pItem->str); + taosMemoryFree(pItem->str); pItem->str = tmp; pItem->stype = stype; return 0; @@ -366,9 +366,9 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) { if (taosArrayPush(pCfg->array, pItem) == NULL) { if (pItem->dtype == CFG_DTYPE_STRING) { - free(pItem->str); + taosMemoryFree(pItem->str); } - free(pItem->name); + taosMemoryFree(pItem->name); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -647,7 +647,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { } taosCloseFile(&pFile); - if (line != NULL) tfree(line); + if (line != NULL) taosMemoryFreeClear(line); uInfo("load from cfg file %s success", filepath); return 0; diff --git a/source/util/src/tcrc32c.c b/source/util/src/tcrc32c.c index f7e1060be0..66e9240cd5 100644 --- a/source/util/src/tcrc32c.c +++ b/source/util/src/tcrc32c.c @@ -19,13 +19,13 @@ */ #define _DEFAULT_SOURCE -#include "tcrc32c.h" -#include "tdef.h" - #if !defined(_TD_ARM_) && !defined(_TD_MIPS_) #include #endif +#include "tcrc32c.h" +#include "tdef.h" + #define POLY 0x82f63b78 #define LONG_SHIFT 8192 #define SHORT_SHIFT 256 diff --git a/source/util/src/tdes.c b/source/util/src/tdes.c index a7f5131c26..0e0193a123 100644 --- a/source/util/src/tdes.c +++ b/source/util/src/tdes.c @@ -47,7 +47,7 @@ char* taosDesImp(uint8_t* key, char* src, uint32_t len, int32_t process_mode) { uint8_t processed_block[9] = {0}; key_set key_sets[17]; memset(key_sets, 0, sizeof(key_sets)); - char* dest = calloc(len + 1, 1); + char* dest = taosMemoryCalloc(len + 1, 1); generate_sub_keys(key, key_sets); for (uint32_t block_count = 0; block_count < number_of_blocks; block_count++) { @@ -68,12 +68,12 @@ char* taosDesEncode(int64_t key, char* src, int32_t len) { char* taosDesDecode(int64_t key, char* src, int32_t len) { uint8_t* keyStr = (uint8_t*)(&key); - char* temp = calloc(len + 8, 1); + char* temp = taosMemoryCalloc(len + 8, 1); memcpy(temp, src, len); len += 8; char* decode = taosDesImp(keyStr, temp, len, DECRYPTION_MODE); - free(temp); + taosMemoryFree(temp); return decode; } diff --git a/source/util/src/tencode.c b/source/util/src/tencode.c index 94b4cced46..c40d5b02e6 100644 --- a/source/util/src/tencode.c +++ b/source/util/src/tencode.c @@ -44,7 +44,7 @@ void tCoderClear(SCoder* pCoder) { pNode = TD_SLIST_HEAD(&(pCoder->stack)); if (pNode == NULL) break; TD_SLIST_POP(&(pCoder->stack)); - free(pNode); + taosMemoryFree(pNode); } } @@ -55,7 +55,7 @@ int32_t tStartEncode(SCoder* pCoder) { if (pCoder->data) { if (pCoder->size - pCoder->pos < sizeof(int32_t)) return -1; - pNode = malloc(sizeof(*pNode)); + pNode = taosMemoryMalloc(sizeof(*pNode)); if (pNode == NULL) return -1; pNode->data = pCoder->data; @@ -93,7 +93,7 @@ void tEndEncode(SCoder* pCoder) { TD_CODER_MOVE_POS(pCoder, len); - free(pNode); + taosMemoryFree(pNode); } } @@ -104,7 +104,7 @@ int32_t tStartDecode(SCoder* pCoder) { ASSERT(pCoder->type == TD_DECODER); if (tDecodeI32(pCoder, &len) < 0) return -1; - pNode = malloc(sizeof(*pNode)); + pNode = taosMemoryMalloc(sizeof(*pNode)); if (pNode == NULL) return -1; pNode->data = pCoder->data; @@ -133,5 +133,5 @@ void tEndDecode(SCoder* pCoder) { pCoder->pos = pCoder->size + pNode->pos; pCoder->size = pNode->size; - free(pNode); + taosMemoryFree(pNode); } diff --git a/source/util/src/tfunctional.c b/source/util/src/tfunctional.c index c49fbdb504..3b51d0046f 100644 --- a/source/util/src/tfunctional.c +++ b/source/util/src/tfunctional.c @@ -17,21 +17,21 @@ #include "tfunctional.h" tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int32_t numOfArgs) { - tGenericSavedFunc* pSavedFunc = malloc(sizeof(tGenericSavedFunc) + numOfArgs * (sizeof(void*))); + tGenericSavedFunc* pSavedFunc = taosMemoryMalloc(sizeof(tGenericSavedFunc) + numOfArgs * (sizeof(void*))); if (pSavedFunc == NULL) return NULL; pSavedFunc->func = func; return pSavedFunc; } tI32SavedFunc* i32SavedFuncInit(I32VaFunc func, int32_t numOfArgs) { - tI32SavedFunc* pSavedFunc = malloc(sizeof(tI32SavedFunc) + numOfArgs * sizeof(void*)); + tI32SavedFunc* pSavedFunc = taosMemoryMalloc(sizeof(tI32SavedFunc) + numOfArgs * sizeof(void*)); if (pSavedFunc == NULL) return NULL; pSavedFunc->func = func; return pSavedFunc; } tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int32_t numOfArgs) { - tVoidSavedFunc* pSavedFunc = malloc(sizeof(tVoidSavedFunc) + numOfArgs * sizeof(void*)); + tVoidSavedFunc* pSavedFunc = taosMemoryMalloc(sizeof(tVoidSavedFunc) + numOfArgs * sizeof(void*)); if (pSavedFunc == NULL) return NULL; pSavedFunc->func = func; return pSavedFunc; diff --git a/source/util/src/thash.c b/source/util/src/thash.c index aac99bfe28..88e5c12770 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -33,7 +33,7 @@ #define FREE_HASH_NODE(_n) \ do { \ - tfree(_n); \ + taosMemoryFreeClear(_n); \ } while (0); struct SHashNode { @@ -238,7 +238,7 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp capacity = 4; } - SHashObj *pHashObj = (SHashObj *)calloc(1, sizeof(SHashObj)); + SHashObj *pHashObj = (SHashObj *)taosMemoryCalloc(1, sizeof(SHashObj)); if (pHashObj == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -254,26 +254,26 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp ASSERT((pHashObj->capacity & (pHashObj->capacity - 1)) == 0); - pHashObj->hashList = (SHashEntry **)calloc(pHashObj->capacity, sizeof(void *)); + pHashObj->hashList = (SHashEntry **)taosMemoryCalloc(pHashObj->capacity, sizeof(void *)); if (pHashObj->hashList == NULL) { - free(pHashObj); + taosMemoryFree(pHashObj); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } pHashObj->pMemBlock = taosArrayInit(8, sizeof(void *)); if (pHashObj->pMemBlock == NULL) { - free(pHashObj->hashList); - free(pHashObj); + taosMemoryFree(pHashObj->hashList); + taosMemoryFree(pHashObj); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - void *p = calloc(pHashObj->capacity, sizeof(SHashEntry)); + void *p = taosMemoryCalloc(pHashObj->capacity, sizeof(SHashEntry)); if (p == NULL) { taosArrayDestroy(pHashObj->pMemBlock); - free(pHashObj->hashList); - free(pHashObj); + taosMemoryFree(pHashObj->hashList); + taosMemoryFree(pHashObj); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -440,14 +440,14 @@ void* taosHashGetImpl(SHashObj *pHashObj, const void *key, size_t keyLen, void** if (size != NULL) { if (*d == NULL) { *size = pNode->dataLen; - *d = calloc(1, *size); + *d = taosMemoryCalloc(1, *size); if (*d == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } } else if (*size < pNode->dataLen) { *size = pNode->dataLen; - char* tmp = realloc(*d, *size); + char* tmp = taosMemoryRealloc(*d, *size); if (tmp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -567,24 +567,24 @@ void taosHashClear(SHashObj *pHashObj) { taosHashWUnlock(pHashObj); } -// the input paras should be SHashObj **, so the origin input will be set by tfree(*pHashObj) +// the input paras should be SHashObj **, so the origin input will be set by taosMemoryFreeClear(*pHashObj) void taosHashCleanup(SHashObj *pHashObj) { if (pHashObj == NULL) { return; } taosHashClear(pHashObj); - tfree(pHashObj->hashList); + taosMemoryFreeClear(pHashObj->hashList); // destroy mem block size_t memBlock = taosArrayGetSize(pHashObj->pMemBlock); for (int32_t i = 0; i < memBlock; ++i) { void *p = taosArrayGetP(pHashObj->pMemBlock, i); - tfree(p); + taosMemoryFreeClear(p); } taosArrayDestroy(pHashObj->pMemBlock); - free(pHashObj); + taosMemoryFree(pHashObj); } // for profile only @@ -623,7 +623,7 @@ void taosHashTableResize(SHashObj *pHashObj) { } int64_t st = taosGetTimestampUs(); - void *pNewEntryList = realloc(pHashObj->hashList, sizeof(void *) * newCapacity); + void *pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(void *) * newCapacity); if (pNewEntryList == NULL) { // uDebug("cache resize failed due to out of memory, capacity remain:%zu", pHashObj->capacity); return; @@ -632,7 +632,7 @@ void taosHashTableResize(SHashObj *pHashObj) { pHashObj->hashList = pNewEntryList; size_t inc = newCapacity - pHashObj->capacity; - void * p = calloc(inc, sizeof(SHashEntry)); + void * p = taosMemoryCalloc(inc, sizeof(SHashEntry)); for (int32_t i = 0; i < inc; ++i) { pHashObj->hashList[i + pHashObj->capacity] = (void *)((char *)p + i * sizeof(SHashEntry)); @@ -683,7 +683,7 @@ void taosHashTableResize(SHashObj *pHashObj) { } SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, size_t dsize, uint32_t hashVal) { - SHashNode *pNewNode = malloc(sizeof(SHashNode) + keyLen + dsize); + SHashNode *pNewNode = taosMemoryMalloc(sizeof(SHashNode) + keyLen + dsize); if (pNewNode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/util/src/theap.c b/source/util/src/theap.c index 30af0483cc..8c1a1db057 100644 --- a/source/util/src/theap.c +++ b/source/util/src/theap.c @@ -19,7 +19,7 @@ size_t heapSize(Heap* heap) { return heap->nelts; } Heap* heapCreate(HeapCompareFn fn) { - Heap* heap = calloc(1, sizeof(Heap)); + Heap* heap = taosMemoryCalloc(1, sizeof(Heap)); if (heap == NULL) { return NULL; } @@ -30,7 +30,7 @@ Heap* heapCreate(HeapCompareFn fn) { return heap; } -void heapDestroy(Heap* heap) { free(heap); } +void heapDestroy(Heap* heap) { taosMemoryFree(heap); } HeapNode* heapMin(const Heap* heap) { return heap->min; } diff --git a/source/util/src/tidpool.c b/source/util/src/tidpool.c index 705cb0d2d3..b45113942c 100644 --- a/source/util/src/tidpool.c +++ b/source/util/src/tidpool.c @@ -18,12 +18,12 @@ #include "tlog.h" void *taosInitIdPool(int32_t maxId) { - id_pool_t *pIdPool = calloc(1, sizeof(id_pool_t)); + id_pool_t *pIdPool = taosMemoryCalloc(1, sizeof(id_pool_t)); if (pIdPool == NULL) return NULL; - pIdPool->freeList = calloc(maxId, sizeof(bool)); + pIdPool->freeList = taosMemoryCalloc(maxId, sizeof(bool)); if (pIdPool->freeList == NULL) { - free(pIdPool); + taosMemoryFree(pIdPool); return NULL; } @@ -79,13 +79,13 @@ void taosIdPoolCleanUp(id_pool_t *pIdPool) { uDebug("pool:%p is cleaned", pIdPool); - if (pIdPool->freeList) free(pIdPool->freeList); + if (pIdPool->freeList) taosMemoryFree(pIdPool->freeList); taosThreadMutexDestroy(&pIdPool->mutex); memset(pIdPool, 0, sizeof(id_pool_t)); - free(pIdPool); + taosMemoryFree(pIdPool); } int32_t taosIdPoolNumOfUsed(id_pool_t *pIdPool) { @@ -118,7 +118,7 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) { return 0; } - bool *idList = calloc(maxId, sizeof(bool)); + bool *idList = taosMemoryCalloc(maxId, sizeof(bool)); if (idList == NULL) { return -1; } @@ -131,7 +131,7 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) { bool *oldIdList = pIdPool->freeList; pIdPool->freeList = idList; - free(oldIdList); + taosMemoryFree(oldIdList); taosThreadMutexUnlock(&pIdPool->mutex); diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index a85da8cbbf..0efcf517a9 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -255,7 +255,7 @@ int32_t tjsonMakeObject(const SJson* pJson, const char* pName, FToObject func, v if (NULL == pJsonObj) { return TSDB_CODE_FAILED; } - *pObj = calloc(1, objSize); + *pObj = taosMemoryCalloc(1, objSize); if (NULL == *pObj) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/util/src/tlist.c b/source/util/src/tlist.c index 5fccba614b..1d17b4a9e1 100644 --- a/source/util/src/tlist.c +++ b/source/util/src/tlist.c @@ -22,7 +22,7 @@ void tdListInit(SList *list, int32_t eleSize) { } SList *tdListNew(int32_t eleSize) { - SList *list = (SList *)malloc(sizeof(SList)); + SList *list = (SList *)taosMemoryMalloc(sizeof(SList)); if (list == NULL) return NULL; tdListInit(list, eleSize); @@ -33,14 +33,14 @@ void tdListEmpty(SList *list) { SListNode *node; while ((node = TD_DLIST_HEAD(list)) != NULL) { TD_DLIST_POP(list, node); - free(node); + taosMemoryFree(node); } } void *tdListFree(SList *list) { if (list) { tdListEmpty(list); - free(list); + taosMemoryFree(list); } return NULL; @@ -51,7 +51,7 @@ void tdListPrependNode(SList *list, SListNode *node) { TD_DLIST_PREPEND(list, no void tdListAppendNode(SList *list, SListNode *node) { TD_DLIST_APPEND(list, node); } int32_t tdListPrepend(SList *list, void *data) { - SListNode *node = (SListNode *)malloc(sizeof(SListNode) + list->eleSize); + SListNode *node = (SListNode *)taosMemoryMalloc(sizeof(SListNode) + list->eleSize); if (node == NULL) return -1; memcpy((void *)(node->data), data, list->eleSize); @@ -61,7 +61,7 @@ int32_t tdListPrepend(SList *list, void *data) { } int32_t tdListAppend(SList *list, void *data) { - SListNode *node = (SListNode *)calloc(1, sizeof(SListNode) + list->eleSize); + SListNode *node = (SListNode *)taosMemoryCalloc(1, sizeof(SListNode) + list->eleSize); if (node == NULL) return -1; memcpy((void *)(node->data), data, list->eleSize); diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 85db7883cf..ef15f44f8f 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -507,10 +507,10 @@ static void taosCloseLogByFd(TdFilePtr pFile) { static SLogBuff *taosLogBuffNew(int32_t bufSize) { SLogBuff *tLogBuff = NULL; - tLogBuff = calloc(1, sizeof(SLogBuff)); + tLogBuff = taosMemoryCalloc(1, sizeof(SLogBuff)); if (tLogBuff == NULL) return NULL; - LOG_BUF_BUFFER(tLogBuff) = malloc(bufSize); + LOG_BUF_BUFFER(tLogBuff) = taosMemoryMalloc(bufSize); if (LOG_BUF_BUFFER(tLogBuff) == NULL) goto _err; LOG_BUF_START(tLogBuff) = LOG_BUF_END(tLogBuff) = 0; @@ -524,8 +524,8 @@ static SLogBuff *taosLogBuffNew(int32_t bufSize) { return tLogBuff; _err: - tfree(LOG_BUF_BUFFER(tLogBuff)); - tfree(tLogBuff); + taosMemoryFreeClear(LOG_BUF_BUFFER(tLogBuff)); + taosMemoryFreeClear(tLogBuff); return NULL; } @@ -688,7 +688,7 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { int32_t compressSize = 163840; int32_t ret = 0; int32_t len = 0; - char *data = malloc(compressSize); + char *data = taosMemoryMalloc(compressSize); // gzFile dstFp = NULL; // srcFp = fopen(srcFileName, "r"); @@ -723,7 +723,7 @@ cmp_end: // if (dstFp) { // gzclose(dstFp); // } - free(data); + taosMemoryFree(data); return ret; } diff --git a/source/util/src/tlosertree.c b/source/util/src/tlosertree.c index 6349ab170c..aeb9ce310b 100644 --- a/source/util/src/tlosertree.c +++ b/source/util/src/tlosertree.c @@ -36,7 +36,7 @@ int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo** pTree, uint32_t numOfSources, int32_t totalEntries = numOfSources << 1u; SMultiwayMergeTreeInfo* pTreeInfo = - (SMultiwayMergeTreeInfo*)calloc(1, sizeof(SMultiwayMergeTreeInfo) + sizeof(STreeNode) * totalEntries); + (SMultiwayMergeTreeInfo*)taosMemoryCalloc(1, sizeof(SMultiwayMergeTreeInfo) + sizeof(STreeNode) * totalEntries); if (pTreeInfo == NULL) { uError("allocate memory for loser-tree failed. reason:%s", strerror(errno)); return TAOS_SYSTEM_ERROR(errno); @@ -76,7 +76,7 @@ void tMergeTreeDestroy(SMultiwayMergeTreeInfo* pTree) { return; } - tfree(pTree); + taosMemoryFreeClear(pTree); } void tMergeTreeAdjust(SMultiwayMergeTreeInfo* pTree, int32_t idx) { diff --git a/source/util/src/tmallocator.c b/source/util/src/tmallocator.c index 057b908a58..0303af07e8 100644 --- a/source/util/src/tmallocator.c +++ b/source/util/src/tmallocator.c @@ -31,7 +31,7 @@ static size_t haUsage(SMemAllocator *pma); SMemAllocator *tdCreateHeapAllocator() { SMemAllocator *pma = NULL; - pma = calloc(1, sizeof(SMemAllocator) + sizeof(SHeapAllocator)); + pma = taosMemoryCalloc(1, sizeof(SMemAllocator) + sizeof(SHeapAllocator)); if (pma) { pma->impl = POINTER_SHIFT(pma, sizeof(SMemAllocator)); pma->malloc = haMalloc; @@ -53,7 +53,7 @@ static void *haMalloc(SMemAllocator *pma, size_t size) { size_t tsize = size + sizeof(size_t); SHeapAllocator *pha = (SHeapAllocator *)(pma->impl); - ptr = malloc(tsize); + ptr = taosMemoryMalloc(tsize); if (ptr) { *(size_t *)ptr = size; ptr = POINTER_SHIFT(ptr, sizeof(size_t)); @@ -97,7 +97,7 @@ static void haFree(SMemAllocator *pma, void *ptr) { /* TODO */ if (ptr) { size_t tsize = *(size_t *)POINTER_SHIFT(ptr, -sizeof(size_t)) + sizeof(size_t); atomic_fetch_sub_64(&(pha->tusage), tsize); - free(POINTER_SHIFT(ptr, -sizeof(size_t))); + taosMemoryFree(POINTER_SHIFT(ptr, -sizeof(size_t))); } } diff --git a/source/util/src/tmempool.c b/source/util/src/tmempool.c index d62e903977..7bf8e94de9 100644 --- a/source/util/src/tmempool.c +++ b/source/util/src/tmempool.c @@ -37,7 +37,7 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) { return NULL; } - pool_p = (pool_t *)malloc(sizeof(pool_t)); + pool_p = (pool_t *)taosMemoryMalloc(sizeof(pool_t)); if (pool_p == NULL) { uError("mempool malloc failed\n"); return NULL; @@ -47,14 +47,14 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) { pool_p->blockSize = blockSize; pool_p->numOfBlock = numOfBlock; - pool_p->pool = (char *)malloc((size_t)(blockSize * numOfBlock)); - pool_p->freeList = (int32_t *)malloc(sizeof(int32_t) * (size_t)numOfBlock); + pool_p->pool = (char *)taosMemoryMalloc((size_t)(blockSize * numOfBlock)); + pool_p->freeList = (int32_t *)taosMemoryMalloc(sizeof(int32_t) * (size_t)numOfBlock); if (pool_p->pool == NULL || pool_p->freeList == NULL) { uError("failed to allocate memory\n"); - tfree(pool_p->freeList); - tfree(pool_p->pool); - tfree(pool_p); + taosMemoryFreeClear(pool_p->freeList); + taosMemoryFreeClear(pool_p->pool); + taosMemoryFreeClear(pool_p); return NULL; } @@ -120,8 +120,8 @@ void taosMemPoolCleanUp(mpool_h handle) { pool_t *pool_p = (pool_t *)handle; taosThreadMutexDestroy(&pool_p->mutex); - if (pool_p->pool) free(pool_p->pool); - if (pool_p->freeList) free(pool_p->freeList); + if (pool_p->pool) taosMemoryFree(pool_p->pool); + if (pool_p->freeList) taosMemoryFree(pool_p->freeList); memset(pool_p, 0, sizeof(*pool_p)); - free(pool_p); + taosMemoryFree(pool_p); } diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index a9d925ac07..d834263b94 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -266,7 +266,7 @@ static SPageInfo* registerPage(SDiskbasedBuf* pBuf, int32_t groupId, int32_t pag pBuf->numOfPages += 1; - SPageInfo* ppi = malloc(sizeof(SPageInfo)); + SPageInfo* ppi = taosMemoryMalloc(sizeof(SPageInfo)); ppi->pageId = pageId; ppi->pData = NULL; @@ -330,7 +330,7 @@ static char* evacOneDataPage(SDiskbasedBuf* pBuf) { assert(d->pn == pn); d->pn = NULL; - tfree(pn); + taosMemoryFreeClear(pn); bufPage = flushPageToDisk(pBuf, d); } @@ -359,7 +359,7 @@ static SPageInfo* getPageInfoFromPayload(void* page) { int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMemBufSize, const char* id, const char* dir) { - *pBuf = calloc(1, sizeof(SDiskbasedBuf)); + *pBuf = taosMemoryCalloc(1, sizeof(SDiskbasedBuf)); SDiskbasedBuf* pPBuf = *pBuf; if (pPBuf == NULL) { @@ -386,7 +386,7 @@ int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMem // init id hash table _hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT); pPBuf->groupSet = taosHashInit(10, fn, true, false); - pPBuf->assistBuf = malloc(pPBuf->pageSize + 2); // EXTRA BYTES + pPBuf->assistBuf = taosMemoryMalloc(pPBuf->pageSize + 2); // EXTRA BYTES pPBuf->all = taosHashInit(10, fn, true, false); char path[PATH_MAX] = {0}; @@ -422,7 +422,7 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t groupId, int32_t* pageId) { pi = *(SPageInfo**)pItem->data; pi->used = true; *pageId = pi->pageId; - tfree(pItem); + taosMemoryFreeClear(pItem); } else { // create a new pageinfo // register new id in this group *pageId = (++pBuf->allocateId); @@ -441,7 +441,7 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t groupId, int32_t* pageId) { // allocate buf if (availablePage == NULL) { - pi->pData = calloc(1, getAllocPageSize(pBuf->pageSize)); // add extract bytes in case of zipped buffer increased. + pi->pData = taosMemoryCalloc(1, getAllocPageSize(pBuf->pageSize)); // add extract bytes in case of zipped buffer increased. } else { pi->pData = availablePage; } @@ -483,7 +483,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) { } if (availablePage == NULL) { - (*pi)->pData = calloc(1, getAllocPageSize(pBuf->pageSize)); + (*pi)->pData = taosMemoryCalloc(1, getAllocPageSize(pBuf->pageSize)); } else { (*pi)->pData = availablePage; } @@ -564,15 +564,15 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) { } taosRemoveFile(pBuf->path); - tfree(pBuf->path); + taosMemoryFreeClear(pBuf->path); SArray** p = taosHashIterate(pBuf->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); + taosMemoryFreeClear(pi->pData); + taosMemoryFreeClear(pi); } taosArrayDestroy(*p); @@ -588,9 +588,9 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) { taosHashCleanup(pBuf->groupSet); taosHashCleanup(pBuf->all); - tfree(pBuf->id); - tfree(pBuf->assistBuf); - tfree(pBuf); + taosMemoryFreeClear(pBuf->id); + taosMemoryFreeClear(pBuf->assistBuf); + taosMemoryFreeClear(pBuf); } SPageInfo* getLastPageInfo(SIDList pList) { @@ -625,8 +625,8 @@ void dBufSetBufPageRecycled(SDiskbasedBuf* pBuf, void* pPage) { // add this pageinfo into the free page info list SListNode* pNode = tdListPopNode(pBuf->lruList, ppi->pn); - tfree(ppi->pData); - tfree(pNode); + taosMemoryFreeClear(ppi->pData); + taosMemoryFreeClear(pNode); tdListAppend(pBuf->freePgList, &ppi); } diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index f19a17fdb6..9e55df44cf 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -163,13 +163,13 @@ static SProcQueue *taosProcQueueInit(int32_t size) { pQueue->bufferShmid = shmId; if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) { - free(pQueue); + taosMemoryFree(pQueue); return NULL; } if (tsem_init(&pQueue->sem, 1, 0) != 0) { taosProcDestroyMutex(pQueue->mutex, &pQueue->mutexShmid); - free(pQueue); + taosMemoryFree(pQueue); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -177,7 +177,7 @@ static SProcQueue *taosProcQueueInit(int32_t size) { if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) { taosProcDestroyMutex(pQueue->mutex, &pQueue->mutexShmid); tsem_destroy(&pQueue->sem); - free(pQueue); + taosMemoryFree(pQueue); return NULL; } @@ -195,7 +195,7 @@ static void taosProcQueueCleanup(SProcQueue *pQueue) { uDebug("proc:%s, queue:%p clean up", pQueue->name, pQueue); taosProcDestroyMutex(pQueue->mutex, &pQueue->mutexShmid); tsem_destroy(&pQueue->sem); - free(pQueue); + taosMemoryFree(pQueue); } } @@ -337,7 +337,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea } SProcObj *taosProcInit(const SProcCfg *pCfg) { - SProcObj *pProc = calloc(1, sizeof(SProcObj)); + SProcObj *pProc = taosMemoryCalloc(1, sizeof(SProcObj)); if (pProc == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -350,7 +350,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { pProc->pParentQueue = taosProcQueueInit(pCfg->parentQueueSize); if (pProc->pChildQueue == NULL || pProc->pParentQueue == NULL) { taosProcQueueCleanup(pProc->pChildQueue); - free(pProc); + taosMemoryFree(pProc); return NULL; } @@ -447,7 +447,7 @@ void taosProcCleanup(SProcObj *pProc) { taosProcStop(pProc); taosProcQueueCleanup(pProc->pChildQueue); taosProcQueueCleanup(pProc->pParentQueue); - free(pProc); + taosMemoryFree(pProc); } } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 70f2871f41..b01e1ea1da 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -57,7 +57,7 @@ typedef struct STaosQall { } STaosQall; STaosQueue *taosOpenQueue() { - STaosQueue *queue = calloc(1, sizeof(STaosQueue)); + STaosQueue *queue = taosMemoryCalloc(1, sizeof(STaosQueue)); if (queue == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -96,11 +96,11 @@ void taosCloseQueue(STaosQueue *queue) { while (pNode) { pTemp = pNode; pNode = pNode->next; - free(pTemp); + taosMemoryFree(pTemp); } taosThreadMutexDestroy(&queue->mutex); - free(queue); + taosMemoryFree(queue); uDebug("queue:%p is closed", queue); } @@ -126,7 +126,7 @@ int32_t taosQueueSize(STaosQueue *queue) { } void *taosAllocateQitem(int32_t size) { - STaosQnode *pNode = calloc(1, sizeof(STaosQnode) + size); + STaosQnode *pNode = taosMemoryCalloc(1, sizeof(STaosQnode) + size); if (pNode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -143,7 +143,7 @@ void taosFreeQitem(void *pItem) { char *temp = pItem; temp -= sizeof(STaosQnode); uTrace("item:%p, node:%p is freed", pItem, temp); - free(temp); + taosMemoryFree(temp); } int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { @@ -193,9 +193,9 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) { return code; } -STaosQall *taosAllocateQall() { return calloc(1, sizeof(STaosQall)); } +STaosQall *taosAllocateQall() { return taosMemoryCalloc(1, sizeof(STaosQall)); } -void taosFreeQall(STaosQall *qall) { free(qall); } +void taosFreeQall(STaosQall *qall) { taosMemoryFree(qall); } int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) { int32_t code = 0; @@ -248,7 +248,7 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) { void taosResetQitems(STaosQall *qall) { qall->current = qall->start; } STaosQset *taosOpenQset() { - STaosQset *qset = calloc(sizeof(STaosQset), 1); + STaosQset *qset = taosMemoryCalloc(sizeof(STaosQset), 1); if (qset == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -277,7 +277,7 @@ void taosCloseQset(STaosQset *qset) { taosThreadMutexDestroy(&qset->mutex); tsem_destroy(&qset->sem); - free(qset); + taosMemoryFree(qset); uDebug("qset:%p is closed", qset); } diff --git a/source/util/src/tref.c b/source/util/src/tref.c index 86633fe07a..2e4c33bc87 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -65,15 +65,15 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) { taosThreadOnce(&tsRefModuleInit, taosInitRefModule); - nodeList = calloc(sizeof(SRefNode *), (size_t)max); + nodeList = taosMemoryCalloc(sizeof(SRefNode *), (size_t)max); if (nodeList == NULL) { terrno = TSDB_CODE_REF_NO_MEMORY; return -1; } - lockedBy = calloc(sizeof(int64_t), (size_t)max); + lockedBy = taosMemoryCalloc(sizeof(int64_t), (size_t)max); if (lockedBy == NULL) { - free(nodeList); + taosMemoryFree(nodeList); terrno = TSDB_CODE_REF_NO_MEMORY; return -1; } @@ -102,8 +102,8 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) { uTrace("rsetId:%d is opened, max:%d, fp:%p refSetNum:%d", rsetId, max, fp, tsRefSetNum); } else { rsetId = TSDB_CODE_REF_FULL; - free(nodeList); - free(lockedBy); + taosMemoryFree(nodeList); + taosMemoryFree(lockedBy); uTrace("run out of Ref ID, maximum:%d refSetNum:%d", TSDB_REF_OBJECTS, tsRefSetNum); } @@ -162,7 +162,7 @@ int64_t taosAddRef(int32_t rsetId, void *p) { return -1; } - pNode = calloc(sizeof(SRefNode), 1); + pNode = taosMemoryCalloc(sizeof(SRefNode), 1); if (pNode == NULL) { terrno = TSDB_CODE_REF_NO_MEMORY; return -1; @@ -445,7 +445,7 @@ static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove) { uTrace("rsetId:%d p:%p rid:%" PRId64 " is removed, count:%d, free mem: %p", rsetId, pNode->p, rid, pSet->count, pNode); (*pSet->fp)(pNode->p); - free(pNode); + taosMemoryFree(pNode); taosDecRsetCount(pSet); } @@ -490,8 +490,8 @@ static void taosDecRsetCount(SRefSet *pSet) { pSet->max = 0; pSet->fp = NULL; - tfree(pSet->nodeList); - tfree(pSet->lockedBy); + taosMemoryFreeClear(pSet->nodeList); + taosMemoryFreeClear(pSet->lockedBy); tsRefSetNum--; uTrace("rsetId:%d is cleaned, refSetNum:%d count:%d", pSet->rsetId, tsRefSetNum, pSet->count); diff --git a/source/util/src/tsched.c b/source/util/src/tsched.c index 316c1f7ec1..2deba5077b 100644 --- a/source/util/src/tsched.c +++ b/source/util/src/tsched.c @@ -42,20 +42,20 @@ static void *taosProcessSchedQueue(void *param); static void taosDumpSchedulerStatus(void *qhandle, void *tmrId); void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *label) { - SSchedQueue *pSched = (SSchedQueue *)calloc(sizeof(SSchedQueue), 1); + SSchedQueue *pSched = (SSchedQueue *)taosMemoryCalloc(sizeof(SSchedQueue), 1); if (pSched == NULL) { uError("%s: no enough memory for pSched", label); return NULL; } - pSched->queue = (SSchedMsg *)calloc(sizeof(SSchedMsg), queueSize); + pSched->queue = (SSchedMsg *)taosMemoryCalloc(sizeof(SSchedMsg), queueSize); if (pSched->queue == NULL) { uError("%s: no enough memory for queue", label); taosCleanUpScheduler(pSched); return NULL; } - pSched->qthread = calloc(sizeof(TdThread), numOfThreads); + pSched->qthread = taosMemoryCalloc(sizeof(TdThread), numOfThreads); if (pSched->qthread == NULL) { uError("%s: no enough memory for qthread", label); taosCleanUpScheduler(pSched); @@ -220,9 +220,9 @@ void taosCleanUpScheduler(void *param) { taosTmrStopA(&pSched->pTimer); } - if (pSched->queue) free(pSched->queue); - if (pSched->qthread) free(pSched->qthread); - free(pSched); // fix memory leak + if (pSched->queue) taosMemoryFree(pSched->queue); + if (pSched->qthread) taosMemoryFree(pSched->qthread); + taosMemoryFree(pSched); // fix memory leak } // for debug purpose, dump the scheduler status every 1min. diff --git a/source/util/src/tskiplist.c b/source/util/src/tskiplist.c index f7e56b6f31..118fe58d2e 100644 --- a/source/util/src/tskiplist.c +++ b/source/util/src/tskiplist.c @@ -28,7 +28,7 @@ static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t static void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **direction, SSkipListNode *pNode, bool isForward); static bool tSkipListGetPosToPut(SSkipList *pSkipList, SSkipListNode **backward, void *pData); static SSkipListNode *tSkipListNewNode(uint8_t level); -#define tSkipListFreeNode(n) tfree((n)) +#define tSkipListFreeNode(n) taosMemoryFreeClear((n)) static SSkipListNode *tSkipListPutImpl(SSkipList *pSkipList, void *pData, SSkipListNode **direction, bool isForward, bool hasDup); @@ -39,7 +39,7 @@ static FORCE_INLINE int32_t getSkipListRandLevel(SSkipList *pSkipList); SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags, __sl_key_fn_t fn) { - SSkipList *pSkipList = (SSkipList *)calloc(1, sizeof(SSkipList)); + SSkipList *pSkipList = (SSkipList *)taosMemoryCalloc(1, sizeof(SSkipList)); if (pSkipList == NULL) return NULL; if (maxLevel > MAX_SKIP_LIST_LEVEL) { @@ -70,7 +70,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _ } if (SL_IS_THREAD_SAFE(pSkipList)) { - pSkipList->lock = (TdThreadRwlock *)calloc(1, sizeof(TdThreadRwlock)); + pSkipList->lock = (TdThreadRwlock *)taosMemoryCalloc(1, sizeof(TdThreadRwlock)); if (pSkipList->lock == NULL) { tSkipListDestroy(pSkipList); return NULL; @@ -105,17 +105,17 @@ void tSkipListDestroy(SSkipList *pSkipList) { tSkipListFreeNode(pTemp); } - tfree(pSkipList->insertHandleFn); + taosMemoryFreeClear(pSkipList->insertHandleFn); tSkipListUnlock(pSkipList); if (pSkipList->lock != NULL) { taosThreadRwlockDestroy(pSkipList->lock); - tfree(pSkipList->lock); + taosMemoryFreeClear(pSkipList->lock); } tSkipListFreeNode(pSkipList->pHead); tSkipListFreeNode(pSkipList->pTail); - tfree(pSkipList); + taosMemoryFreeClear(pSkipList); } SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData) { @@ -345,7 +345,7 @@ void *tSkipListDestroyIter(SSkipListIterator *iter) { return NULL; } - tfree(iter); + taosMemoryFreeClear(iter); return NULL; } @@ -418,7 +418,7 @@ static void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **direction, S } static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t order) { - SSkipListIterator *iter = calloc(1, sizeof(SSkipListIterator)); + SSkipListIterator *iter = taosMemoryCalloc(1, sizeof(SSkipListIterator)); iter->pSkipList = pSkipList; iter->order = order; @@ -662,7 +662,7 @@ static int32_t initForwardBackwardPtr(SSkipList *pSkipList) { static SSkipListNode *tSkipListNewNode(uint8_t level) { int32_t tsize = sizeof(SSkipListNode) + sizeof(SSkipListNode *) * level * 2; - SSkipListNode *pNode = (SSkipListNode *)calloc(1, tsize); + SSkipListNode *pNode = (SSkipListNode *)taosMemoryCalloc(1, tsize); if (pNode == NULL) return NULL; pNode->level = level; diff --git a/source/util/src/tstrbuild.c b/source/util/src/tstrbuild.c index f191f69986..2aae588046 100644 --- a/source/util/src/tstrbuild.c +++ b/source/util/src/tstrbuild.c @@ -20,7 +20,7 @@ void taosStringBuilderEnsureCapacity(SStringBuilder* sb, size_t size) { size += sb->pos; if (size > sb->size) { size *= 2; - void* tmp = realloc(sb->buf, size); + void* tmp = taosMemoryRealloc(sb->buf, size); if (tmp == NULL) { longjmp(sb->jb, 1); } @@ -39,7 +39,7 @@ char* taosStringBuilderGetResult(SStringBuilder* sb, size_t* len) { } void taosStringBuilderDestroy(SStringBuilder* sb) { - free(sb->buf); + taosMemoryFree(sb->buf); sb->buf = NULL; sb->pos = 0; sb->size = 0; diff --git a/source/util/src/tthread.c b/source/util/src/tthread.c index da76135b68..3a22478729 100644 --- a/source/util/src/tthread.c +++ b/source/util/src/tthread.c @@ -17,7 +17,7 @@ #include "tthread.h" TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) { - TdThread* pthread = (TdThread*)malloc(sizeof(TdThread)); + TdThread* pthread = (TdThread*)taosMemoryMalloc(sizeof(TdThread)); TdThreadAttr thattr; taosThreadAttrInit(&thattr); taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); @@ -25,7 +25,7 @@ TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) { taosThreadAttrDestroy(&thattr); if (ret != 0) { - free(pthread); + taosMemoryFree(pthread); return NULL; } return pthread; @@ -38,7 +38,7 @@ bool taosDestoryThread(TdThread* pthread) { taosThreadJoin(*pthread, NULL); } - free(pthread); + taosMemoryFree(pthread); return true; } diff --git a/source/util/src/ttimer.c b/source/util/src/ttimer.c index 5e59e61ea1..fecc58c236 100644 --- a/source/util/src/ttimer.c +++ b/source/util/src/ttimer.c @@ -141,7 +141,7 @@ static void timerAddRef(tmr_obj_t* timer) { atomic_add_fetch_8(&timer->refCount, static void timerDecRef(tmr_obj_t* timer) { if (atomic_sub_fetch_8(&timer->refCount, 1) == 0) { - free(timer); + taosMemoryFree(timer); } } @@ -351,7 +351,7 @@ tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* ha return NULL; } - tmr_obj_t* timer = (tmr_obj_t*)calloc(1, sizeof(tmr_obj_t)); + tmr_obj_t* timer = (tmr_obj_t*)taosMemoryCalloc(1, sizeof(tmr_obj_t)); if (timer == NULL) { tmrError("%s failed to allocated memory for new timer object.", ctrl->label); return NULL; @@ -513,7 +513,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* han } static void taosTmrModuleInit(void) { - tmrCtrls = malloc(sizeof(tmr_ctrl_t) * tsMaxTmrCtrl); + tmrCtrls = taosMemoryMalloc(sizeof(tmr_ctrl_t) * tsMaxTmrCtrl); if (tmrCtrls == NULL) { tmrError("failed to allocate memory for timer controllers."); return; @@ -539,7 +539,7 @@ static void taosTmrModuleInit(void) { } wheel->nextScanAt = now + wheel->resolution; wheel->index = 0; - wheel->slots = (tmr_obj_t**)calloc(wheel->size, sizeof(tmr_obj_t*)); + wheel->slots = (tmr_obj_t**)taosMemoryCalloc(wheel->size, sizeof(tmr_obj_t*)); if (wheel->slots == NULL) { tmrError("failed to allocate wheel slots"); return; @@ -548,7 +548,7 @@ static void taosTmrModuleInit(void) { } timerMap.count = 0; - timerMap.slots = (timer_list_t*)calloc(timerMap.size, sizeof(timer_list_t)); + timerMap.slots = (timer_list_t*)taosMemoryCalloc(timerMap.size, sizeof(timer_list_t)); if (timerMap.slots == NULL) { tmrError("failed to allocate hash map"); return; @@ -609,7 +609,7 @@ void taosTmrCleanUp(void* handle) { for (int32_t i = 0; i < tListLen(wheels); i++) { time_wheel_t* wheel = wheels + i; taosThreadMutexDestroy(&wheel->mutex); - free(wheel->slots); + taosMemoryFree(wheel->slots); } taosThreadMutexDestroy(&tmrCtrlMutex); @@ -619,12 +619,12 @@ void taosTmrCleanUp(void* handle) { tmr_obj_t* t = list->timers; while (t != NULL) { tmr_obj_t* next = t->mnext; - free(t); + taosMemoryFree(t); t = next; } } - free(timerMap.slots); - free(tmrCtrls); + taosMemoryFree(timerMap.slots); + taosMemoryFree(tmrCtrls); tmrCtrls = NULL; unusedTmrCtrl = NULL; diff --git a/source/util/src/tutil.c b/source/util/src/tutil.c index dc982596ad..8133e4d237 100644 --- a/source/util/src/tutil.c +++ b/source/util/src/tutil.c @@ -147,7 +147,7 @@ char **strsplit(char *z, const char *delim, int32_t *num) { *num = 0; int32_t size = 4; - char **split = malloc(POINTER_BYTES * size); + char **split = taosMemoryMalloc(POINTER_BYTES * size); for (char *p = strsep(&z, delim); p != NULL; p = strsep(&z, delim)) { size_t len = strlen(p); @@ -158,7 +158,7 @@ char **strsplit(char *z, const char *delim, int32_t *num) { split[(*num)++] = p; if ((*num) >= size) { size = (size << 1); - split = realloc(split, POINTER_BYTES * size); + split = taosMemoryRealloc(split, POINTER_BYTES * size); assert(NULL != split); } } @@ -349,7 +349,7 @@ char *strbetween(char *string, char *begin, char *end) { char *_end = strstr(_begin + strlen(begin), end); int32_t size = (int32_t)(_end - _begin); if (_end != NULL && size > 0) { - result = (char *)calloc(1, size); + result = (char *)taosMemoryCalloc(1, size); memcpy(result, _begin + strlen(begin), size - +strlen(begin)); } } diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 044896d7a5..992ec74b5b 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -22,7 +22,7 @@ typedef void *(*ThreadFp)(void *param); int32_t tQWorkerInit(SQWorkerPool *pool) { pool->qset = taosOpenQset(); - pool->workers = calloc(pool->max, sizeof(SQWorker)); + pool->workers = taosMemoryCalloc(pool->max, sizeof(SQWorker)); if (pool->workers == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -60,7 +60,7 @@ void tQWorkerCleanup(SQWorkerPool *pool) { } } - tfree(pool->workers); + taosMemoryFreeClear(pool->workers); taosCloseQset(pool->qset); taosThreadMutexDestroy(&pool->mutex); @@ -142,7 +142,7 @@ void tQWorkerFreeQueue(SQWorkerPool *pool, STaosQueue *queue) { int32_t tWWorkerInit(SWWorkerPool *pool) { pool->nextId = 0; - pool->workers = calloc(pool->max, sizeof(SWWorker)); + pool->workers = taosMemoryCalloc(pool->max, sizeof(SWWorker)); if (pool->workers == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -184,7 +184,7 @@ void tWWorkerCleanup(SWWorkerPool *pool) { } } - tfree(pool->workers); + taosMemoryFreeClear(pool->workers); taosThreadMutexDestroy(&pool->mutex); uInfo("worker:%s is closed", pool->name); diff --git a/source/util/test/hashTest.cpp b/source/util/test/hashTest.cpp index f4d2d9b47b..99f5a761c5 100644 --- a/source/util/test/hashTest.cpp +++ b/source/util/test/hashTest.cpp @@ -158,7 +158,7 @@ void acquireRleaseTest() { const char *str2 = "aaaaaaa"; const char *str3 = "123456789"; - data.p = (char *)malloc(10); + data.p = (char *)taosMemoryMalloc(10); strcpy(data.p, str1); code = taosHashPut(hashTable, &key, sizeof(key), &data, sizeof(data)); @@ -177,7 +177,7 @@ void acquireRleaseTest() { strcpy(pdata->p, str3); - data.p = (char *)malloc(10); + data.p = (char *)taosMemoryMalloc(10); strcpy(data.p, str2); code = taosHashPut(hashTable, &key, sizeof(key), &data, sizeof(data)); ASSERT_EQ(code, 0); @@ -187,14 +187,14 @@ void acquireRleaseTest() { printf("%s,expect:%s", pdata->p, str3); ASSERT_TRUE(strcmp(pdata->p, str3) == 0); - tfree(pdata->p); + taosMemoryFreeClear(pdata->p); taosHashRelease(hashTable, pdata); num = taosHashGetSize(hashTable); ASSERT_EQ(num, 1); taosHashCleanup(hashTable); - tfree(data.p); + taosMemoryFreeClear(data.p); } } diff --git a/source/util/test/skiplistTest.cpp b/source/util/test/skiplistTest.cpp index 0b629f64aa..7110b21aa9 100644 --- a/source/util/test/skiplistTest.cpp +++ b/source/util/test/skiplistTest.cpp @@ -32,7 +32,7 @@ void doubleSkipListTest() { size = 0; // tSkipListNewNodeInfo(pSkipList, &level, &size); - // auto d = (SSkipListNode*)calloc(1, size + sizeof(double) * 2); + // auto d = (SSkipListNode*)taosMemoryCalloc(1, size + sizeof(double) * 2); // d->level = level; double key = 0.997; @@ -59,7 +59,7 @@ void doubleSkipListTest() { } if (size > 0) { - tfree(pNodes); + taosMemoryFreeClear(pNodes); } } @@ -83,7 +83,7 @@ void randKeyTest() { int32_t s = 0; tSkipListNewNodeInfo(pSkipList, &level, &s); - auto d = (SSkipListNode*)calloc(1, s + sizeof(int32_t) * 2); + auto d = (SSkipListNode*)taosMemoryCalloc(1, s + sizeof(int32_t) * 2); d->level = level; int32_t* key = (int32_t*)SL_GET_NODE_KEY(pSkipList, d); @@ -115,7 +115,7 @@ void stringKeySkiplistTest() { int32_t headsize = 0; tSkipListNewNodeInfo(pSkipList, &level, &headsize); - auto pNode = (SSkipListNode*)calloc(1, headsize + max_key_size + sizeof(double)); + auto pNode = (SSkipListNode*)taosMemoryCalloc(1, headsize + max_key_size + sizeof(double)); pNode->level = level; char* d = SL_GET_NODE_DATA(pNode); @@ -127,7 +127,7 @@ void stringKeySkiplistTest() { tSkipListNewNodeInfo(pSkipList, &level, &headsize); - pNode = (SSkipListNode*)calloc(1, headsize + max_key_size + sizeof(double)); + pNode = (SSkipListNode*)taosMemoryCalloc(1, headsize + max_key_size + sizeof(double)); pNode->level = level; d = SL_GET_NODE_DATA(pNode); @@ -153,7 +153,7 @@ void stringKeySkiplistTest() { tSkipListDestroy(pSkipList); - free(pRes); + taosMemoryFree(pRes); #endif tSkipListDestroy(pSkipList); @@ -167,7 +167,7 @@ void stringKeySkiplistTest() { int32_t n = sprintf(k, "abc_%d_%d", i, i); tSkipListNewNodeInfo(pSkipList, &level, &headsize); - auto pNode = (SSkipListNode*)calloc(1, headsize + 20 + sizeof(double)); + auto pNode = (SSkipListNode*)taosMemoryCalloc(1, headsize + 20 + sizeof(double)); pNode->level = level; char* d = SL_GET_NODE_DATA(pNode); @@ -197,7 +197,7 @@ void stringKeySkiplistTest() { tSkipListRemoveNode(pSkipList, pres[0]); if (num > 0) { - tfree(pres); + taosMemoryFreeClear(pres); } } @@ -219,7 +219,7 @@ void skiplistPerformanceTest() { int32_t unit = MAX_SKIP_LIST_LEVEL * POINTER_BYTES * 2 + sizeof(double) * 2 + sizeof(int16_t); - char* total = (char*)calloc(1, unit * size); + char* total = (char*)taosMemoryCalloc(1, unit * size); char* p = total; for (int32_t i = 0; i < size; ++i) { @@ -277,7 +277,7 @@ void skiplistPerformanceTest() { assert(SL_GET_SIZE(pSkipList) == size); tSkipListDestroy(pSkipList); - tfree(total); + taosMemoryFreeClear(total); } // todo not support duplicated key yet @@ -288,7 +288,7 @@ void duplicatedKeyTest() { for (int32_t j = 0; j < 5; ++j) { int32_t level, size; tSkipListNewNodeInfo(pSkipList, &level, &size); - SSkipListNode* d = (SSkipListNode*)calloc(1, size + sizeof(int32_t)); + SSkipListNode* d = (SSkipListNode*)taosMemoryCalloc(1, size + sizeof(int32_t)); d->level = level; int32_t* key = (int32_t*)SL_GET_NODE_KEY(pSkipList, d); key[0] = i; @@ -358,9 +358,9 @@ TEST(testCase, skiplist_test) { printf("-----%lf\n", pNodes[i]->key.dKey); } printf("the range query result size is: %d\n", size); - tfree(pNodes); + taosMemoryFreeClear(pNodes); - SSkipListKey *pKeys = malloc(sizeof(SSkipListKey) * 20); + SSkipListKey *pKeys = taosMemoryMalloc(sizeof(SSkipListKey) * 20); for (int32_t i = 0; i < 8; i += 2) { pKeys[i].dKey = i * 0.997; pKeys[i].nType = TSDB_DATA_TYPE_DOUBLE; @@ -372,9 +372,9 @@ TEST(testCase, skiplist_test) { for (int32_t i = 0; i < r; ++i) { // printf("%lf ", pNodes[i]->key.dKey); } - tfree(pNodes); + taosMemoryFreeClear(pNodes); - free(pKeys);*/ + taosMemoryFree(pKeys);*/ } #endif \ No newline at end of file diff --git a/source/util/test/stringTest.cpp b/source/util/test/stringTest.cpp index 95fba0cd3e..dee5fb30d3 100644 --- a/source/util/test/stringTest.cpp +++ b/source/util/test/stringTest.cpp @@ -33,35 +33,35 @@ TEST(testCase, string_replace_test) { EXPECT_EQ(strlen(ret), 7); EXPECT_STREQ("7017027", ret); - free(ret); + taosMemoryFree(ret); char t4[] = "a01a02b03c04d05"; ret = strreplace(t4, "0", "9999999999"); EXPECT_EQ(strlen(ret), 5 * 10 + 10); EXPECT_STREQ("a99999999991a99999999992b99999999993c99999999994d99999999995", ret); - free(ret); + taosMemoryFree(ret); char t5[] = "abc"; ret = strreplace(t5, "abc", "12345678901234567890"); EXPECT_EQ(strlen(ret), 20); EXPECT_STREQ("12345678901234567890", ret); - free(ret); + taosMemoryFree(ret); char t6[] = "abc"; ret = strreplace(t6, "def", "abc"); EXPECT_EQ(strlen(ret), 3); EXPECT_STREQ("abc", ret); - free(ret); + taosMemoryFree(ret); char t7[] = "abcde000000000000001234"; ret = strreplace(t7, "ab", "0000000"); EXPECT_EQ(strlen(ret), 28); EXPECT_STREQ("0000000cde000000000000001234", ret); - free(ret); + taosMemoryFree(ret); char t8[] = "abc\ndef"; char t[] = {10, 0}; @@ -72,21 +72,21 @@ TEST(testCase, string_replace_test) { EXPECT_EQ(strlen(ret), 8); EXPECT_STREQ("abc\\ndef", ret); - free(ret); + taosMemoryFree(ret); char t9[] = "abc\\ndef"; ret = strreplace(t9, "\\n", "\n"); EXPECT_EQ(strlen(ret), 7); EXPECT_STREQ("abc\ndef", ret); - free(ret); + taosMemoryFree(ret); char t10[] = "abcdef"; ret = strreplace(t10, "", "0"); EXPECT_EQ(strlen(ret), 6); EXPECT_STREQ("abcdef", ret); - free(ret); + taosMemoryFree(ret); } #endif diff --git a/source/util/test/trefTest.c b/source/util/test/trefTest.c index a439a84562..3174d57aef 100644 --- a/source/util/test/trefTest.c +++ b/source/util/test/trefTest.c @@ -38,7 +38,7 @@ void *addRef(void *param) { printf("a"); id = random() % pSpace->refNum; if (pSpace->rid[id] <= 0) { - pSpace->p[id] = malloc(128); + pSpace->p[id] = taosMemoryMalloc(128); pSpace->rid[id] = taosAddRef(pSpace->rsetId, pSpace->p[id]); } taosUsleep(100); @@ -84,7 +84,7 @@ void *acquireRelease(void *param) { } void myfree(void *p) { - free(p); + taosMemoryFree(p); } void *openRefSpace(void *param) { @@ -98,8 +98,8 @@ void *openRefSpace(void *param) { return NULL; } - pSpace->p = (void **) calloc(sizeof(void *), pSpace->refNum); - pSpace->rid = calloc(pSpace->refNum, sizeof(int64_t)); + pSpace->p = (void **) taosMemoryCalloc(sizeof(void *), pSpace->refNum); + pSpace->rid = taosMemoryCalloc(pSpace->refNum, sizeof(int64_t)); TdThreadAttr thattr; taosThreadAttrInit(&thattr); @@ -121,7 +121,7 @@ void *openRefSpace(void *param) { taosCloseRef(pSpace->rsetId); uInfo("rsetId:%d main thread exit", pSpace->rsetId); - free(pSpace->p); + taosMemoryFree(pSpace->p); pSpace->p = NULL; return NULL; @@ -159,8 +159,8 @@ int main(int argc, char *argv[]) { taosInitLog("tref.log", 10); - SRefSpace *pSpaceList = (SRefSpace *) calloc(sizeof(SRefSpace), threads); - TdThread *pThreadList = (TdThread *) calloc(sizeof(TdThread), threads); + SRefSpace *pSpaceList = (SRefSpace *) taosMemoryCalloc(sizeof(SRefSpace), threads); + TdThread *pThreadList = (TdThread *) taosMemoryCalloc(sizeof(TdThread), threads); TdThreadAttr thattr; taosThreadAttrInit(&thattr); @@ -182,8 +182,8 @@ int main(int argc, char *argv[]) { int num = taosListRef(); printf("\nnumber of references:%d\n", num); - free(pSpaceList); - free(pThreadList); + taosMemoryFree(pSpaceList); + taosMemoryFree(pThreadList); taosCloseLog(); diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 7651e8708f..de1050850d 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -227,13 +227,13 @@ int stmt_scol_func3(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -332,11 +332,11 @@ int stmt_scol_func3(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -357,13 +357,13 @@ int stmt_scol_func4(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1000 * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1000*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -455,11 +455,11 @@ int stmt_scol_func4(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -854,18 +854,18 @@ int stmt_funcb_autoctb1(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -1040,12 +1040,12 @@ int stmt_funcb_autoctb1(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -1067,18 +1067,18 @@ int stmt_funcb_autoctb2(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -1253,12 +1253,12 @@ int stmt_funcb_autoctb2(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -1281,18 +1281,18 @@ int stmt_funcb_autoctb3(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -1442,12 +1442,12 @@ int stmt_funcb_autoctb3(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -1472,18 +1472,18 @@ int stmt_funcb_autoctb4(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*5); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*5); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -1597,12 +1597,12 @@ int stmt_funcb_autoctb4(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -1625,18 +1625,18 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -1786,12 +1786,12 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -1814,18 +1814,18 @@ int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -2001,12 +2001,12 @@ int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -2031,18 +2031,18 @@ int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -2219,12 +2219,12 @@ int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -2246,18 +2246,18 @@ int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -2444,12 +2444,12 @@ int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -2473,18 +2473,18 @@ int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { char bin[10][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 1 * 10); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10); - int *lb = malloc(10 * sizeof(int)); + int *lb = taosMemoryMalloc(10 * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); // int one_null = 1; int one_not_null = 0; - char* is_null = malloc(sizeof(char) * 10); - char* no_null = malloc(sizeof(char) * 10); + char* is_null = taosMemoryMalloc(sizeof(char) * 10); + char* no_null = taosMemoryMalloc(sizeof(char) * 10); for (int i = 0; i < 10; ++i) { lb[i] = 40; @@ -2671,12 +2671,12 @@ int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); - free(tags); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); + taosMemoryFree(tags); return 0; } @@ -2697,13 +2697,13 @@ int stmt_funcb1(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -2830,11 +2830,11 @@ int stmt_funcb1(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -2854,13 +2854,13 @@ int stmt_funcb2(TAOS_STMT *stmt) { char bin[18000][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(18000 * sizeof(int)); + int *lb = taosMemoryMalloc(18000 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); - char* is_null = malloc(sizeof(char) * 18000); - char* no_null = malloc(sizeof(char) * 18000); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 18000); + char* no_null = taosMemoryMalloc(sizeof(char) * 18000); for (int i = 0; i < 18000; ++i) { lb[i] = 40; @@ -2988,11 +2988,11 @@ int stmt_funcb2(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -3012,13 +3012,13 @@ int stmt_funcb3(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -3151,11 +3151,11 @@ int stmt_funcb3(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -3177,13 +3177,13 @@ int stmt_funcb4(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -3310,11 +3310,11 @@ int stmt_funcb4(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -3336,13 +3336,13 @@ int stmt_funcb5(TAOS_STMT *stmt) { char bin[18000][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(18000 * sizeof(int)); + int *lb = taosMemoryMalloc(18000 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); - char* is_null = malloc(sizeof(char) * 18000); - char* no_null = malloc(sizeof(char) * 18000); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 18000); + char* no_null = taosMemoryMalloc(sizeof(char) * 18000); for (int i = 0; i < 18000; ++i) { lb[i] = 40; @@ -3463,11 +3463,11 @@ int stmt_funcb5(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -3480,12 +3480,12 @@ int stmt_funcb_ssz1(TAOS_STMT *stmt) { int b[30000]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 30000 * 3000); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 30000 * 3000); - int *lb = malloc(30000 * sizeof(int)); + int *lb = taosMemoryMalloc(30000 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); - char* no_null = malloc(sizeof(int) * 200000); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); + char* no_null = taosMemoryMalloc(sizeof(int) * 200000); for (int i = 0; i < 30000; ++i) { lb[i] = 40; @@ -3548,10 +3548,10 @@ int stmt_funcb_ssz1(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(no_null); return 0; } @@ -3571,13 +3571,13 @@ int stmt_funcb_s1(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -3705,11 +3705,11 @@ int stmt_funcb_s1(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -3733,13 +3733,13 @@ int stmt_funcb_sc1(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -3867,11 +3867,11 @@ int stmt_funcb_sc1(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -3891,13 +3891,13 @@ int stmt_funcb_sc2(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 900000 * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -4027,11 +4027,11 @@ int stmt_funcb_sc2(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -4051,13 +4051,13 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) { char bin[60][40]; } v = {0}; - v.ts = malloc(sizeof(int64_t) * 60); + v.ts = taosMemoryMalloc(sizeof(int64_t) * 60); - int *lb = malloc(60 * sizeof(int)); + int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 60*10); - char* is_null = malloc(sizeof(char) * 60); - char* no_null = malloc(sizeof(char) * 60); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 60*10); + char* is_null = taosMemoryMalloc(sizeof(char) * 60); + char* no_null = taosMemoryMalloc(sizeof(char) * 60); for (int i = 0; i < 60; ++i) { lb[i] = 40; @@ -4184,11 +4184,11 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) { unsigned long long endtime = getCurrentTime(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - free(v.ts); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v.ts); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -4247,7 +4247,7 @@ int sql_perf1(TAOS *taos) { TAOS_RES *result; for (int i = 0; i < 3000; i++) { - sql[i] = calloc(1, 1048576); + sql[i] = taosMemoryCalloc(1, 1048576); } int len = 0; @@ -4279,7 +4279,7 @@ int sql_perf1(TAOS *taos) { printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60)); for (int i = 0; i < 3000; i++) { - free(sql[i]); + taosMemoryFree(sql[i]); } return 0; @@ -4291,11 +4291,11 @@ int sql_perf1(TAOS *taos) { //one table 60 records one time int sql_perf_s1(TAOS *taos) { - char **sql = calloc(1, sizeof(char*) * 360000); + char **sql = taosMemoryCalloc(1, sizeof(char*) * 360000); TAOS_RES *result; for (int i = 0; i < 360000; i++) { - sql[i] = calloc(1, 9000); + sql[i] = taosMemoryCalloc(1, 9000); } int len = 0; @@ -4332,10 +4332,10 @@ int sql_perf_s1(TAOS *taos) { printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60)); for (int i = 0; i < 360000; i++) { - free(sql[i]); + taosMemoryFree(sql[i]); } - free(sql); + taosMemoryFree(sql); return 0; } @@ -4347,7 +4347,7 @@ int sql_s_perf1(TAOS *taos) { TAOS_RES *result; for (int i = 0; i < 3000; i++) { - sql[i] = calloc(1, 1048576); + sql[i] = taosMemoryCalloc(1, 1048576); } int len = 0; @@ -4379,7 +4379,7 @@ int sql_s_perf1(TAOS *taos) { printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60)); for (int i = 0; i < 3000; i++) { - free(sql[i]); + taosMemoryFree(sql[i]); } return 0; @@ -5066,7 +5066,7 @@ int main(int argc, char *argv[]) exit(1); } - TdThread *pThreadList = (TdThread *) calloc(sizeof(TdThread), 4); + TdThread *pThreadList = (TdThread *) taosMemoryCalloc(sizeof(TdThread), 4); TdThreadAttr thattr; taosThreadAttrInit(&thattr); diff --git a/tests/script/api/stmtBatchTest.c b/tests/script/api/stmtBatchTest.c index a6c20d282e..b671b8bc06 100644 --- a/tests/script/api/stmtBatchTest.c +++ b/tests/script/api/stmtBatchTest.c @@ -50,19 +50,19 @@ unsigned long long getCurrentTime(){ } static int stmt_bind_case_001(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -221,33 +221,33 @@ static int stmt_bind_case_001(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } static int stmt_bind_case_002(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -406,33 +406,33 @@ static int stmt_bind_case_002(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } static int stmt_bind_case_003(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -528,32 +528,32 @@ static int stmt_bind_case_003(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } static int stmt_bind_case_004(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum * 2)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum * 2)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * 2 * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * 2 * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -730,32 +730,32 @@ static int stmt_bind_case_004(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } static int stmt_bind_error_case_001(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum * 2)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum * 2)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * 2 * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * 2 * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -925,33 +925,33 @@ static int stmt_bind_error_case_001(TAOS_STMT *stmt, int tableNum, int rowsOfPer unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } static int stmt_bind_error_case_002(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum * 2)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum * 2)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * 2 * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * 2 * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -1110,32 +1110,32 @@ static int stmt_bind_error_case_002(TAOS_STMT *stmt, int tableNum, int rowsOfPer unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } static int stmt_bind_error_case_003(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum * 2)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum * 2)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * 2 * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * 2 * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -1314,14 +1314,14 @@ static int stmt_bind_error_case_003(TAOS_STMT *stmt, int tableNum, int rowsOfPer unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -2058,19 +2058,19 @@ static void runCase(TAOS *taos) { static int stmt_bind_case_001_long(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum, int64_t* startTs) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = *startTs; @@ -2231,14 +2231,14 @@ static int stmt_bind_case_001_long(TAOS_STMT *stmt, int tableNum, int rowsOfPerC unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -2325,19 +2325,19 @@ static void runCase_long(TAOS *taos) { test scene: insert into tb1 (ts,f1) values (?,?) */ static int stmt_specifyCol_bind_case_001(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -2455,14 +2455,14 @@ static int stmt_specifyCol_bind_case_001(TAOS_STMT *stmt, int tableNum, int rows unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -2472,19 +2472,19 @@ static int stmt_specifyCol_bind_case_001(TAOS_STMT *stmt, int tableNum, int rows test scene: insert into ? (ts,f1) values (?,?) */ static int stmt_specifyCol_bind_case_002(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -2602,14 +2602,14 @@ static int stmt_specifyCol_bind_case_002(TAOS_STMT *stmt, int tableNum, int rows unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -2619,19 +2619,19 @@ static int stmt_specifyCol_bind_case_002(TAOS_STMT *stmt, int tableNum, int rows test scene: insert into tb1 (ts,f1) values (?,?) */ static int stmt_specifyCol_bind_case_001_maxRows(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -2728,14 +2728,14 @@ static int stmt_specifyCol_bind_case_001_maxRows(TAOS_STMT *stmt, int tableNum, unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -3205,20 +3205,20 @@ static void SpecifyColumnBatchCase(TAOS *taos) { test scene: insert into tb1 (ts,f1) values (?,?) */ static int stmt_specifyCol_bind_case_001_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int one_not_null = 0; int64_t tts = 1591060628000; @@ -3387,34 +3387,34 @@ static int stmt_specifyCol_bind_case_001_autoCreateTbl(TAOS_STMT *stmt, int tabl unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(tags); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(tags); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } static int stmt_specifyCol_bind_case_002_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int one_not_null = 0; int64_t tts = 1591060628000; @@ -3583,35 +3583,35 @@ static int stmt_specifyCol_bind_case_002_autoCreateTbl(TAOS_STMT *stmt, int tabl unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(tags); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(tags); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } // some tags are null static int stmt_specifyCol_bind_case_003_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int one_not_null = 0; int one_is_null = 1; @@ -3781,35 +3781,35 @@ static int stmt_specifyCol_bind_case_003_autoCreateTbl(TAOS_STMT *stmt, int tabl unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(tags); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(tags); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } // specify tags field, and not support , then is error case static int stmt_specifyCol_bind_case_004_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int one_not_null = 0; int64_t tts = 1591060628000; @@ -3978,15 +3978,15 @@ static int stmt_specifyCol_bind_case_004_autoCreateTbl(TAOS_STMT *stmt, int tabl unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(tags); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(tags); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -4413,19 +4413,19 @@ char * taos_stmt_errstr(TAOS_STMT *stmt) 用于在其他stmt API 返回错误( 3. 返回的错误码对于的错误消息; */ static int stmt_specifyCol_bind_error_case_001(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -4570,32 +4570,32 @@ static int stmt_specifyCol_bind_error_case_001(TAOS_STMT *stmt, int tableNum, in unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } static int stmt_specifyCol_bind_error_case_002(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { - sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + sampleValue* v = (sampleValue *)taosMemoryCalloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; - v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); - v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->ts = (int64_t *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)taosMemoryMalloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); - int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + int *lb = (int *)taosMemoryMalloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); - TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); - char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); - char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = taosMemoryMalloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); int64_t tts = 1591060628000; @@ -4715,14 +4715,14 @@ static int stmt_specifyCol_bind_error_case_002(TAOS_STMT *stmt, int tableNum, in unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); - free(v->ts); - free(v->br); - free(v->nr); - free(v); - free(lb); - free(params); - free(is_null); - free(no_null); + taosMemoryFree(v->ts); + taosMemoryFree(v->br); + taosMemoryFree(v->nr); + taosMemoryFree(v); + taosMemoryFree(lb); + taosMemoryFree(params); + taosMemoryFree(is_null); + taosMemoryFree(no_null); return 0; } @@ -5079,8 +5079,8 @@ int main(int argc, char *argv[]) #if 0 printf("server:%s, threadNum:%d, rows:%d\n\n", serverIp, threadNum, g_rows); - TdThread *pThreadList = (TdThread *) calloc(sizeof(TdThread), (size_t)threadNum); - ThreadInfo* threadInfo = (ThreadInfo *) calloc(sizeof(ThreadInfo), (size_t)threadNum); + TdThread *pThreadList = (TdThread *) taosMemoryCalloc(sizeof(TdThread), (size_t)threadNum); + ThreadInfo* threadInfo = (ThreadInfo *) taosMemoryCalloc(sizeof(ThreadInfo), (size_t)threadNum); ThreadInfo* tInfo = threadInfo; for (int i = 0; i < threadNum; i++) { @@ -5105,8 +5105,8 @@ int main(int argc, char *argv[]) taosThreadJoin(pThreadList[i], NULL); } - free(pThreadList); - free(threadInfo); + taosMemoryFree(pThreadList); + taosMemoryFree(threadInfo); #endif taos = taos_connect(serverIp, "root", "taosdata", NULL, 0); diff --git a/tests/script/api/stmtTest.c b/tests/script/api/stmtTest.c index 46f1c7c8f8..02d65de567 100644 --- a/tests/script/api/stmtTest.c +++ b/tests/script/api/stmtTest.c @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) { execute_simple_sql(taos, "use test"); execute_simple_sql(taos, "create table super(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 tinyint, c8 bool, c9 nchar(8), c10 timestamp) tags (t1 int, t2 bigint, t3 float, t4 double, t5 binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8))"); - char *sql = calloc(1, 1024*1024); + char *sql = taosMemoryCalloc(1, 1024*1024); int sqlLen = 0; sqlLen = sprintf(sql, "create table"); for (int i = 0; i < 10; i++) { diff --git a/tests/script/api/stmt_function.c b/tests/script/api/stmt_function.c index a5427844d7..62f8fab29f 100644 --- a/tests/script/api/stmt_function.c +++ b/tests/script/api/stmt_function.c @@ -50,7 +50,7 @@ void taos_stmt_init_test() { } void taos_stmt_preprare_test() { printf("start taos_stmt_prepare test\n"); - char *stmt_sql = calloc(1, 1048576); + char *stmt_sql = taosMemoryCalloc(1, 1048576); TAOS_STMT *stmt = NULL; assert(taos_stmt_prepare(stmt, stmt_sql, 0) != 0); void *taos = NULL; @@ -93,14 +93,14 @@ void taos_stmt_preprare_test() { assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); assert(taos_stmt_close(stmt) == 0); - free(stmt_sql); + taosMemoryFree(stmt_sql); printf("finish taos_stmt_prepare test\n"); } void taos_stmt_set_tbname_test() { printf("start taos_stmt_set_tbname test\n"); TAOS_STMT *stmt = NULL; - char *name = calloc(1, 200); + char *name = taosMemoryCalloc(1, 200); // ASM ERROR // assert(taos_stmt_set_tbname(stmt, name) != 0); void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0); @@ -115,14 +115,14 @@ void taos_stmt_set_tbname_test() { stmt = taos_stmt_init(taos); assert(stmt != NULL); assert(taos_stmt_set_tbname(stmt, name) != 0); - char* stmt_sql = calloc(1, 1000); + char* stmt_sql = taosMemoryCalloc(1, 1000); sprintf(stmt_sql, "insert into ? values (?,?)"); assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); sprintf(name, "super"); assert(stmt != NULL); assert(taos_stmt_set_tbname(stmt, name) == 0); - free(name); - free(stmt_sql); + taosMemoryFree(name); + taosMemoryFree(stmt_sql); taos_stmt_close(stmt); printf("finish taos_stmt_set_tbname test\n"); } @@ -130,8 +130,8 @@ void taos_stmt_set_tbname_test() { void taos_stmt_set_tbname_tags_test() { printf("start taos_stmt_set_tbname_tags test\n"); TAOS_STMT *stmt = NULL; - char *name = calloc(1,20); - TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND)); + char *name = taosMemoryCalloc(1,20); + TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND)); // ASM ERROR // assert(taos_stmt_set_tbname_tags(stmt, name, tags) != 0); void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0); @@ -146,7 +146,7 @@ void taos_stmt_set_tbname_tags_test() { execute_simple_sql(taos, "create table tb using super tags (1)"); stmt = taos_stmt_init(taos); assert(stmt != NULL); - char* stmt_sql = calloc(1, 1000); + char* stmt_sql = taosMemoryCalloc(1, 1000); sprintf(stmt_sql, "insert into ? using super tags (?) values (?,?)"); assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); assert(taos_stmt_set_tbname_tags(stmt, name, tags) != 0); @@ -159,9 +159,9 @@ void taos_stmt_set_tbname_tags_test() { tags->length = &tags->buffer_length; tags->is_null = NULL; assert(taos_stmt_set_tbname_tags(stmt, name, tags) == 0); - free(stmt_sql); - free(name); - free(tags); + taosMemoryFree(stmt_sql); + taosMemoryFree(name); + taosMemoryFree(tags); taos_stmt_close(stmt); printf("finish taos_stmt_set_tbname_tags test\n"); } @@ -169,7 +169,7 @@ void taos_stmt_set_tbname_tags_test() { void taos_stmt_set_sub_tbname_test() { printf("start taos_stmt_set_sub_tbname test\n"); TAOS_STMT *stmt = NULL; - char *name = calloc(1, 200); + char *name = taosMemoryCalloc(1, 200); // ASM ERROR // assert(taos_stmt_set_sub_tbname(stmt, name) != 0); void *taos = taos_connect("127.0.0.1","root","taosdata",NULL,0); @@ -184,7 +184,7 @@ void taos_stmt_set_sub_tbname_test() { execute_simple_sql(taos, "create table tb using super tags (1)"); stmt = taos_stmt_init(taos); assert(stmt != NULL); - char* stmt_sql = calloc(1, 1000); + char* stmt_sql = taosMemoryCalloc(1, 1000); sprintf(stmt_sql, "insert into ? values (?,?)"); assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); assert(taos_stmt_set_sub_tbname(stmt, name) != 0); @@ -192,8 +192,8 @@ void taos_stmt_set_sub_tbname_test() { assert(taos_stmt_set_sub_tbname(stmt, name) == 0); // assert(taos_load_table_info(taos, "super, tb") == 0); // assert(taos_stmt_set_sub_tbname(stmt, name) == 0); - free(name); - free(stmt_sql); + taosMemoryFree(name); + taosMemoryFree(stmt_sql); assert(taos_stmt_close(stmt) == 0); printf("finish taos_stmt_set_sub_tbname test\n"); } @@ -213,12 +213,12 @@ void taos_stmt_bind_param_test() { execute_simple_sql(taos, "use stmt_test"); execute_simple_sql(taos, "create table super(ts timestamp, c1 int)"); stmt = taos_stmt_init(taos); - char* stmt_sql = calloc(1, 1000); + char* stmt_sql = taosMemoryCalloc(1, 1000); sprintf(stmt_sql, "insert into ? values (?,?)"); assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); assert(taos_stmt_bind_param(stmt, binds) != 0); - free(binds); - TAOS_BIND *params = calloc(2, sizeof(TAOS_BIND)); + taosMemoryFree(binds); + TAOS_BIND *params = taosMemoryCalloc(2, sizeof(TAOS_BIND)); int64_t ts = (int64_t)1591060628000; params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; params[0].buffer_length = sizeof(uint64_t); @@ -234,8 +234,8 @@ void taos_stmt_bind_param_test() { assert(taos_stmt_bind_param(stmt, params) != 0); assert(taos_stmt_set_tbname(stmt, "super") == 0); assert(taos_stmt_bind_param(stmt, params) == 0); - free(params); - free(stmt_sql); + taosMemoryFree(params); + taosMemoryFree(stmt_sql); taos_stmt_close(stmt); printf("finish taos_stmt_bind_param test\n"); } @@ -271,11 +271,11 @@ void taos_stmt_add_batch_test() { execute_simple_sql(taos, "create table super(ts timestamp, c1 int)"); stmt = taos_stmt_init(taos); assert(stmt != NULL); - char* stmt_sql = calloc(1, 1000); + char* stmt_sql = taosMemoryCalloc(1, 1000); sprintf(stmt_sql, "insert into ? values (?,?)"); assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); assert(taos_stmt_add_batch(stmt) != 0); - TAOS_BIND *params = calloc(2, sizeof(TAOS_BIND)); + TAOS_BIND *params = taosMemoryCalloc(2, sizeof(TAOS_BIND)); int64_t ts = (int64_t)1591060628000; params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; params[0].buffer_length = sizeof(uint64_t); @@ -291,8 +291,8 @@ void taos_stmt_add_batch_test() { assert(taos_stmt_set_tbname(stmt, "super") == 0); assert(taos_stmt_bind_param(stmt, params) == 0); assert(taos_stmt_add_batch(stmt) == 0); - free(params); - free(stmt_sql); + taosMemoryFree(params); + taosMemoryFree(stmt_sql); assert(taos_stmt_close(stmt) == 0); printf("finish taos_stmt_add_batch test\n"); } @@ -313,11 +313,11 @@ void taos_stmt_execute_test() { stmt = taos_stmt_init(taos); assert(stmt != NULL); assert(taos_stmt_execute(stmt) != 0); - char* stmt_sql = calloc(1, 1000); + char* stmt_sql = taosMemoryCalloc(1, 1000); sprintf(stmt_sql, "insert into ? values (?,?)"); assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); assert(taos_stmt_execute(stmt) != 0); - TAOS_BIND *params = calloc(2, sizeof(TAOS_BIND)); + TAOS_BIND *params = taosMemoryCalloc(2, sizeof(TAOS_BIND)); int64_t ts = (int64_t)1591060628000; params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; params[0].buffer_length = sizeof(uint64_t); @@ -336,8 +336,8 @@ void taos_stmt_execute_test() { assert(taos_stmt_execute(stmt) != 0); assert(taos_stmt_add_batch(stmt) == 0); assert(taos_stmt_execute(stmt) == 0); - free(params); - free(stmt_sql); + taosMemoryFree(params); + taosMemoryFree(stmt_sql); assert(taos_stmt_close(stmt) == 0); printf("finish taos_stmt_execute test\n"); } @@ -345,7 +345,7 @@ void taos_stmt_execute_test() { void taos_stmt_use_result_query(void *taos, char *col, int type) { TAOS_STMT *stmt = taos_stmt_init(taos); assert(stmt != NULL); - char *stmt_sql = calloc(1, 1024); + char *stmt_sql = taosMemoryCalloc(1, 1024); struct { int64_t c1; int32_t c2; @@ -372,7 +372,7 @@ void taos_stmt_use_result_query(void *taos, char *col, int type) { sprintf(stmt_sql, "select * from stmt_test.t1 where %s = ?", col); printf("stmt_sql: %s\n", stmt_sql); assert(taos_stmt_prepare(stmt, stmt_sql, 0) == 0); - TAOS_BIND *params = calloc(1, sizeof(TAOS_BIND)); + TAOS_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_BIND)); params->buffer_type = type; params->is_null = NULL; switch(type){ @@ -434,8 +434,8 @@ void taos_stmt_use_result_query(void *taos, char *col, int type) { assert(result != NULL); print_result(result); assert(taos_stmt_close(stmt) == 0); - free(params); - free(stmt_sql); + taosMemoryFree(params); + taosMemoryFree(stmt_sql); taos_free_result(result); } diff --git a/tests/script/http/httpTest.c b/tests/script/http/httpTest.c index 0fe4265a9d..0298d5507d 100644 --- a/tests/script/http/httpTest.c +++ b/tests/script/http/httpTest.c @@ -77,8 +77,8 @@ void execute(void *params) { char ip[] = "127.0.0.1"; int port = 6041; char page[] = "rest/sql"; - char *unique = calloc(1, 1024); - char *sql = calloc(1, 1024); + char *unique = taosMemoryCalloc(1, 1024); + char *sql = taosMemoryCalloc(1, 1024); ThreadObj *pThread = (ThreadObj *)params; printf("Thread %d started\n", pThread->threadId); sprintf(unique, "rest/sql/db%d",pThread->threadId); @@ -94,8 +94,8 @@ void execute(void *params) { sprintf(sql, "insert into t%d values (now + %ds, %d)", pThread->threadId, i, pThread->threadId); post(ip,port,unique, sql); } - free(unique); - free(sql); + taosMemoryFree(unique); + taosMemoryFree(sql); return; } @@ -103,7 +103,7 @@ void multiThread() { int numOfThreads = 100; int numOfTables = 100; int numOfRows = 1; - ThreadObj *threads = calloc((size_t)numOfThreads, sizeof(ThreadObj)); + ThreadObj *threads = taosMemoryCalloc((size_t)numOfThreads, sizeof(ThreadObj)); for (int i = 0; i < numOfThreads; i++) { ThreadObj *pthread = threads + i; TdThreadAttr thattr; @@ -117,7 +117,7 @@ void multiThread() { for (int i = 0; i < numOfThreads; i++) { taosThreadJoin(threads[i].pid, NULL); } - free(threads); + taosMemoryFree(threads); } int main() { diff --git a/tests/script/http/httpTestSqlUtc.c b/tests/script/http/httpTestSqlUtc.c index c6c5829b95..b93f134623 100644 --- a/tests/script/http/httpTestSqlUtc.c +++ b/tests/script/http/httpTestSqlUtc.c @@ -77,8 +77,8 @@ void execute(void *params) { char ip[] = "127.0.0.1"; int port = 6041; char page[] = "rest/sqlutc"; - char *unique = calloc(1, 1024); - char *sql = calloc(1, 1024); + char *unique = taosMemoryCalloc(1, 1024); + char *sql = taosMemoryCalloc(1, 1024); ThreadObj *pThread = (ThreadObj *)params; printf("Thread %d started\n", pThread->threadId); sprintf(unique, "rest/sqlutc/db%d",pThread->threadId); @@ -94,8 +94,8 @@ void execute(void *params) { sprintf(sql, "insert into t%d values (now + %ds, %d)", pThread->threadId, i, pThread->threadId); post(ip,port,unique, sql); } - free(unique); - free(sql); + taosMemoryFree(unique); + taosMemoryFree(sql); return; } @@ -103,7 +103,7 @@ void multiThread() { int numOfThreads = 100; int numOfTables = 100; int numOfRows = 1; - ThreadObj *threads = calloc((size_t)numOfThreads, sizeof(ThreadObj)); + ThreadObj *threads = taosMemoryCalloc((size_t)numOfThreads, sizeof(ThreadObj)); for (int i = 0; i < numOfThreads; i++) { ThreadObj *pthread = threads + i; TdThreadAttr thattr; @@ -117,7 +117,7 @@ void multiThread() { for (int i = 0; i < numOfThreads; i++) { taosThreadJoin(threads[i].pid, NULL); } - free(threads); + taosMemoryFree(threads); } int main() { diff --git a/tests/script/http/httpTestSqlt.c b/tests/script/http/httpTestSqlt.c index 400428f471..d8d21ac137 100644 --- a/tests/script/http/httpTestSqlt.c +++ b/tests/script/http/httpTestSqlt.c @@ -77,8 +77,8 @@ void execute(void *params) { char ip[] = "127.0.0.1"; int port = 6041; char page[] = "rest/sqlt"; - char *unique = calloc(1, 1024); - char *sql = calloc(1, 1024); + char *unique = taosMemoryCalloc(1, 1024); + char *sql = taosMemoryCalloc(1, 1024); ThreadObj *pThread = (ThreadObj *)params; printf("Thread %d started\n", pThread->threadId); sprintf(unique, "rest/sqlt/db%d",pThread->threadId); @@ -94,8 +94,8 @@ void execute(void *params) { sprintf(sql, "insert into t%d values (now + %ds, %d)", pThread->threadId, i, pThread->threadId); post(ip,port,unique, sql); } - free(unique); - free(sql); + taosMemoryFree(unique); + taosMemoryFree(sql); return; } @@ -103,7 +103,7 @@ void multiThread() { int numOfThreads = 100; int numOfTables = 100; int numOfRows = 1; - ThreadObj *threads = calloc((size_t)numOfThreads, sizeof(ThreadObj)); + ThreadObj *threads = taosMemoryCalloc((size_t)numOfThreads, sizeof(ThreadObj)); for (int i = 0; i < numOfThreads; i++) { ThreadObj *pthread = threads + i; TdThreadAttr thattr; @@ -117,7 +117,7 @@ void multiThread() { for (int i = 0; i < numOfThreads; i++) { taosThreadJoin(threads[i].pid, NULL); } - free(threads); + taosMemoryFree(threads); } int main() { diff --git a/tests/script/sh/sum_double.c b/tests/script/sh/sum_double.c index b4b0b81a06..0297920361 100644 --- a/tests/script/sh/sum_double.c +++ b/tests/script/sh/sum_double.c @@ -71,14 +71,14 @@ void sum_double_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* int sum_double_init(SUdfInit* buf) { buf->maybe_null=1; - buf->ptr = malloc(sizeof(int)); + buf->ptr = taosMemoryMalloc(sizeof(int)); printf("sum_double init\n"); return 0; } void sum_double_destroy(SUdfInit* buf) { - free(buf->ptr); + taosMemoryFree(buf->ptr); printf("sum_double destroy\n"); } diff --git a/tests/test/c/create_table.c b/tests/test/c/create_table.c index 5e539780f4..4fca7d6245 100644 --- a/tests/test/c/create_table.c +++ b/tests/test/c/create_table.c @@ -173,7 +173,7 @@ void showTables() { void *threadFunc(void *param) { SThreadInfo *pInfo = (SThreadInfo *)param; - char *qstr = malloc(batchNumOfTbl * batchNumOfRow * 128); + char *qstr = taosMemoryMalloc(batchNumOfTbl * batchNumOfRow * 128); int32_t code = 0; TAOS *con = taos_connect(NULL, "root", "taosdata", NULL, 0); @@ -284,7 +284,7 @@ void *threadFunc(void *param) { } taos_close(con); - free(qstr); + taosMemoryFree(qstr); return 0; } @@ -403,7 +403,7 @@ int32_t main(int32_t argc, char *argv[]) { TdThreadAttr thattr; taosThreadAttrInit(&thattr); taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); - SThreadInfo *pInfo = (SThreadInfo *)calloc(numOfThreads, sizeof(SThreadInfo)); + SThreadInfo *pInfo = (SThreadInfo *)taosMemoryCalloc(numOfThreads, sizeof(SThreadInfo)); // int64_t numOfTablesPerThread = numOfTables / numOfThreads; // numOfTables = numOfTablesPerThread * numOfThreads; @@ -466,5 +466,5 @@ int32_t main(int32_t argc, char *argv[]) { } taosThreadAttrDestroy(&thattr); - free(pInfo); + taosMemoryFree(pInfo); } diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 15022f648a..205bc0a639 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -275,7 +275,7 @@ int32_t init_env() { taos_free_result(pRes); // create row value - g_pRowValue = (char*)calloc(1, g_stConfInfo.numOfColumn * 16 + 128); + g_pRowValue = (char*)taosMemoryCalloc(1, g_stConfInfo.numOfColumn * 16 + 128); if (NULL == g_pRowValue) { return -1; } @@ -472,7 +472,7 @@ int32_t syncWriteData() { taos_free_result(pRes); char* buffer = NULL; - buffer = (char*)malloc(MAX_SQL_STR_LEN); + buffer = (char*)taosMemoryMalloc(MAX_SQL_STR_LEN); if (NULL == buffer) { return -1; } @@ -505,7 +505,7 @@ int32_t syncWriteData() { int code = queryDB(pConn, buffer); if (0 != code){ fprintf(stderr, "insert data error!\n"); - tfree(buffer); + taosMemoryFreeClear(buffer); return -1; } @@ -517,7 +517,7 @@ int32_t syncWriteData() { } } } - tfree(buffer); + taosMemoryFreeClear(buffer); return totalMsgs; } @@ -539,7 +539,7 @@ int32_t syncWriteDataByRatio() { taos_free_result(pRes); char* buffer = NULL; - buffer = (char*)malloc(MAX_SQL_STR_LEN); + buffer = (char*)taosMemoryMalloc(MAX_SQL_STR_LEN); if (NULL == buffer) { return -1; } @@ -597,7 +597,7 @@ int32_t syncWriteDataByRatio() { int code = queryDB(pConn, buffer); if (0 != code){ fprintf(stderr, "insert data error!\n"); - tfree(buffer); + taosMemoryFreeClear(buffer); return -1; } @@ -611,7 +611,7 @@ int32_t syncWriteDataByRatio() { } } pPrint("expect insert rows: T1[%d] T2[%d], actual insert rows: T1[%d] T2[%d]\n", g_stConfInfo.totalRowsOfPerTbl, g_stConfInfo.totalRowsOfT2, insertedOfT1, insertedOfT2); - tfree(buffer); + taosMemoryFreeClear(buffer); return totalMsgs; } @@ -719,7 +719,7 @@ int main(int32_t argc, char *argv[]) { perf_loop(tmq, topic_list, totalMsgs, walLogSize); - tfree(g_pRowValue); + taosMemoryFreeClear(g_pRowValue); taosFprintfFile(g_fp, "\n"); taosCloseFile(&g_fp); return 0; diff --git a/tests/tsim/src/simParse.c b/tests/tsim/src/simParse.c index 7a1950611e..a0721941e3 100644 --- a/tests/tsim/src/simParse.c +++ b/tests/tsim/src/simParse.c @@ -156,17 +156,17 @@ SScript *simBuildScriptObj(char *fileName) { if (cmdLine[i].jump == 0) cmdLine[i].jump = numOfLines; } - SScript *script = malloc(sizeof(SScript)); + SScript *script = taosMemoryMalloc(sizeof(SScript)); memset(script, 0, sizeof(SScript)); script->type = SIM_SCRIPT_TYPE_MAIN; script->numOfLines = numOfLines; tstrncpy(script->fileName, fileName, sizeof(script->fileName)); - script->optionBuffer = malloc(optionOffset); + script->optionBuffer = taosMemoryMalloc(optionOffset); memcpy(script->optionBuffer, optionBuffer, optionOffset); - script->lines = malloc(sizeof(SCmdLine) * numOfLines); + script->lines = taosMemoryMalloc(sizeof(SCmdLine) * numOfLines); memcpy(script->lines, cmdLine, sizeof(SCmdLine) * numOfLines); return script; @@ -239,7 +239,7 @@ SScript *simParseScript(char *fileName) { return NULL; } } - if(buffer != NULL) free(buffer); + if(buffer != NULL) taosMemoryFree(buffer); taosCloseFile(&pFile); script = simBuildScriptObj(fileName); diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index eddcd3afc2..eb5fb68264 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -60,16 +60,16 @@ void simFreeScript(SScript *script) { simDebug("script:%s, background thread joined", bgScript->fileName); taos_close(bgScript->taos); - tfree(bgScript->lines); - tfree(bgScript->optionBuffer); - tfree(bgScript); + taosMemoryFreeClear(bgScript->lines); + taosMemoryFreeClear(bgScript->optionBuffer); + taosMemoryFreeClear(bgScript); } simDebug("script:%s, is cleaned", script->fileName); taos_close(script->taos); - tfree(script->lines); - tfree(script->optionBuffer); - tfree(script); + taosMemoryFreeClear(script->lines); + taosMemoryFreeClear(script->optionBuffer); + taosMemoryFreeClear(script); } } diff --git a/tools/shell/src/backup/shellCheck.c b/tools/shell/src/backup/shellCheck.c index 919cb0d846..dc18ecd3f8 100644 --- a/tools/shell/src/backup/shellCheck.c +++ b/tools/shell/src/backup/shellCheck.c @@ -72,7 +72,7 @@ static int32_t shellShowTables(TAOS *con, char *db) { int32_t tbIndex = tbNum++; if (tbMallocNum < tbNum) { tbMallocNum = (tbMallocNum * 2 + 1); - char** tbNames1 = realloc(tbNames, tbMallocNum * sizeof(char *)); + char** tbNames1 = taosMemoryRealloc(tbNames, tbMallocNum * sizeof(char *)); if (tbNames1 == NULL) { fprintf(stdout, "failed to malloc tablenames, num:%d\n", tbMallocNum); code = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -81,7 +81,7 @@ static int32_t shellShowTables(TAOS *con, char *db) { tbNames = tbNames1; } - tbNames[tbIndex] = malloc(TSDB_TABLE_NAME_LEN); + tbNames[tbIndex] = taosMemoryMalloc(TSDB_TABLE_NAME_LEN); strncpy(tbNames[tbIndex], (const char *)row[0], TSDB_TABLE_NAME_LEN); if (tbIndex % 100000 == 0 && tbIndex != 0) { fprintf(stdout, "%d tablenames fetched\n", tbIndex); @@ -97,9 +97,9 @@ static int32_t shellShowTables(TAOS *con, char *db) { static void shellFreeTbnames() { for (int32_t i = 0; i < tbNum; ++i) { - free(tbNames[i]); + taosMemoryFree(tbNames[i]); } - free(tbNames); + taosMemoryFree(tbNames); } static void *shellCheckThreadFp(void *arg) { @@ -153,7 +153,7 @@ static void *shellCheckThreadFp(void *arg) { static void shellRunCheckThreads(TAOS *con, SShellArguments *_args) { TdThreadAttr thattr; - ShellThreadObj *threadObj = (ShellThreadObj *)calloc(_args->threadNum, sizeof(ShellThreadObj)); + ShellThreadObj *threadObj = (ShellThreadObj *)taosMemoryCalloc(_args->threadNum, sizeof(ShellThreadObj)); for (int t = 0; t < _args->threadNum; ++t) { ShellThreadObj *pThread = threadObj + t; pThread->threadIndex = t; @@ -177,7 +177,7 @@ static void shellRunCheckThreads(TAOS *con, SShellArguments *_args) { for (int t = 0; t < _args->threadNum; ++t) { taos_close(threadObj[t].taos); } - free(threadObj); + taosMemoryFree(threadObj); } void shellCheck(TAOS *con, SShellArguments *_args) { diff --git a/tools/shell/src/backup/shellDarwin.c b/tools/shell/src/backup/shellDarwin.c index 69c7a7bc4e..93335776ba 100644 --- a/tools/shell/src/backup/shellDarwin.c +++ b/tools/shell/src/backup/shellDarwin.c @@ -206,8 +206,8 @@ int32_t shellReadCommand(TAOS *con, char *command) { char utf8_array[10] = "\0"; Command cmd; memset(&cmd, 0, sizeof(cmd)); - cmd.buffer = (char *)calloc(1, MAX_COMMAND_SIZE); - cmd.command = (char *)calloc(1, MAX_COMMAND_SIZE); + cmd.buffer = (char *)taosMemoryCalloc(1, MAX_COMMAND_SIZE); + cmd.command = (char *)taosMemoryCalloc(1, MAX_COMMAND_SIZE); showOnScreen(&cmd); // Read input. @@ -252,8 +252,8 @@ int32_t shellReadCommand(TAOS *con, char *command) { printf("\n"); if (isReadyGo(&cmd)) { sprintf(command, "%s%s", cmd.buffer, cmd.command); - tfree(cmd.buffer); - tfree(cmd.command); + taosMemoryFreeClear(cmd.buffer); + taosMemoryFreeClear(cmd.command); return 0; } else { updateBuffer(&cmd); @@ -367,7 +367,7 @@ void *shellLoopQuery(void *arg) { taosThreadCleanupPush(cleanup_handler, NULL); - char *command = malloc(MAX_COMMAND_SIZE); + char *command = taosMemoryMalloc(MAX_COMMAND_SIZE); if (command == NULL){ tscError("failed to malloc command"); return NULL; @@ -386,7 +386,7 @@ void *shellLoopQuery(void *arg) { resetTerminalMode(); } while (shellRunCommand(con, command) == 0); - tfree(command); + taosMemoryFreeClear(command); exitShell(); taosThreadCleanupPop(1); @@ -429,7 +429,7 @@ void showOnScreen(Command *cmd) { int size = 0; // Print out the command. - char *total_string = malloc(MAX_COMMAND_SIZE); + char *total_string = taosMemoryMalloc(MAX_COMMAND_SIZE); memset(total_string, '\0', MAX_COMMAND_SIZE); if (strcmp(cmd->buffer, "") == 0) { sprintf(total_string, "%s%s", PROMPT_HEADER, cmd->command); @@ -461,7 +461,7 @@ void showOnScreen(Command *cmd) { str = total_string + size; } - free(total_string); + taosMemoryFree(total_string); /* for (int i = 0; i < size; i++){ */ /* char c = total_string[i]; */ /* if (k % w.ws_col == 0) { */ diff --git a/tools/shell/src/backup/shellImport.c b/tools/shell/src/backup/shellImport.c index 398bcf2280..130c72a20b 100644 --- a/tools/shell/src/backup/shellImport.c +++ b/tools/shell/src/backup/shellImport.c @@ -97,9 +97,9 @@ static void shellCheckTablesSQLFile(const char *directoryName) static void shellMallocSQLFiles() { - shellSQLFiles = (char**)calloc(shellSQLFileNum, sizeof(char*)); + shellSQLFiles = (char**)taosMemoryCalloc(shellSQLFileNum, sizeof(char*)); for (int i = 0; i < shellSQLFileNum; i++) { - shellSQLFiles[i] = calloc(1, TSDB_FILENAME_LEN); + shellSQLFiles[i] = taosMemoryCalloc(1, TSDB_FILENAME_LEN); } } @@ -130,20 +130,20 @@ static void shellGetDirectoryFileList(char *inputDir) static void shellSourceFile(TAOS *con, char *fptr) { wordexp_t full_path; int read_len = 0; - char * cmd = malloc(tsMaxSQLStringLen); + char * cmd = taosMemoryMalloc(tsMaxSQLStringLen); size_t cmd_len = 0; char * line = NULL; if (wordexp(fptr, &full_path, 0) != 0) { fprintf(stderr, "ERROR: illegal file name\n"); - free(cmd); + taosMemoryFree(cmd); return; } char *fname = full_path.we_wordv[0]; if (fname == NULL) { fprintf(stderr, "ERROR: invalid filename\n"); - free(cmd); + taosMemoryFree(cmd); return; } @@ -152,7 +152,7 @@ static void shellSourceFile(TAOS *con, char *fptr) { fprintf(stderr, "ERROR: file %s is not exist\n", fptr); wordfree(&full_path); - free(cmd); + taosMemoryFree(cmd); return; } @@ -160,7 +160,7 @@ static void shellSourceFile(TAOS *con, char *fptr) { fprintf(stderr, "ERROR: file %s is not readable\n", fptr); wordfree(&full_path); - free(cmd); + taosMemoryFree(cmd); return; } */ @@ -170,7 +170,7 @@ static void shellSourceFile(TAOS *con, char *fptr) { if (pFile == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); wordfree(&full_path); - free(cmd); + taosMemoryFree(cmd); return; } @@ -209,8 +209,8 @@ static void shellSourceFile(TAOS *con, char *fptr) { cmd_len = 0; } - free(cmd); - if(line != NULL) free(line); + taosMemoryFree(cmd); + if(line != NULL) taosMemoryFree(line); wordfree(&full_path); taosCloseFile(&pFile); } @@ -233,7 +233,7 @@ void* shellImportThreadFp(void *arg) static void shellRunImportThreads(SShellArguments* _args) { TdThreadAttr thattr; - ShellThreadObj *threadObj = (ShellThreadObj *)calloc(_args->threadNum, sizeof(ShellThreadObj)); + ShellThreadObj *threadObj = (ShellThreadObj *)taosMemoryCalloc(_args->threadNum, sizeof(ShellThreadObj)); for (int t = 0; t < _args->threadNum; ++t) { ShellThreadObj *pThread = threadObj + t; pThread->threadIndex = t; @@ -260,7 +260,7 @@ static void shellRunImportThreads(SShellArguments* _args) for (int t = 0; t < _args->threadNum; ++t) { taos_close(threadObj[t].taos); } - free(threadObj); + taosMemoryFree(threadObj); } void source_dir(TAOS* con, SShellArguments* _args) { diff --git a/tools/shell/src/backup/shellWindows.c b/tools/shell/src/backup/shellWindows.c index 1244c7b060..92ac7fd721 100644 --- a/tools/shell/src/backup/shellWindows.c +++ b/tools/shell/src/backup/shellWindows.c @@ -239,7 +239,7 @@ void updateBuffer(Command *cmd) { } int isReadyGo(Command *cmd) { - char *total = malloc(MAX_COMMAND_SIZE); + char *total = taosMemoryMalloc(MAX_COMMAND_SIZE); memset(total, 0, MAX_COMMAND_SIZE); sprintf(total, "%s%s", cmd->buffer, cmd->command); @@ -247,11 +247,11 @@ int isReadyGo(Command *cmd) { "(^.*;\\s*$)|(^\\s*$)|(^\\s*exit\\s*$)|(^\\s*q\\s*$)|(^\\s*quit\\s*$)|(^" "\\s*clear\\s*$)"; if (regex_match(total, reg_str, REG_EXTENDED | REG_ICASE)) { - free(total); + taosMemoryFree(total); return 1; } - free(total); + taosMemoryFree(total); return 0; } @@ -268,8 +268,8 @@ void insertChar(Command *cmd, char c) { int32_t shellReadCommand(TAOS *con, char command[]) { Command cmd; memset(&cmd, 0, sizeof(cmd)); - cmd.buffer = (char *)calloc(1, MAX_COMMAND_SIZE); - cmd.command = (char *)calloc(1, MAX_COMMAND_SIZE); + cmd.buffer = (char *)taosMemoryCalloc(1, MAX_COMMAND_SIZE); + cmd.command = (char *)taosMemoryCalloc(1, MAX_COMMAND_SIZE); // Read input. char c; @@ -281,9 +281,9 @@ int32_t shellReadCommand(TAOS *con, char command[]) { case '\r': if (isReadyGo(&cmd)) { sprintf(command, "%s%s", cmd.buffer, cmd.command); - free(cmd.buffer); + taosMemoryFree(cmd.buffer); cmd.buffer = NULL; - free(cmd.command); + taosMemoryFree(cmd.command); cmd.command = NULL; return 0; } else { @@ -301,7 +301,7 @@ int32_t shellReadCommand(TAOS *con, char command[]) { void *shellLoopQuery(void *arg) { TAOS *con = (TAOS *)arg; - char *command = malloc(MAX_COMMAND_SIZE); + char *command = taosMemoryMalloc(MAX_COMMAND_SIZE); if (command == NULL) return NULL; int32_t err = 0; diff --git a/tools/shell/src/shellCommand.c b/tools/shell/src/shellCommand.c index fd993998b8..7cbadfaf5b 100644 --- a/tools/shell/src/shellCommand.c +++ b/tools/shell/src/shellCommand.c @@ -230,7 +230,7 @@ void updateBuffer(Command *cmd) { int isReadyGo(Command *cmd) { assert(cmd->cursorOffset <= cmd->commandSize && cmd->endOffset >= cmd->screenOffset); - char *total = (char *)calloc(1, MAX_COMMAND_SIZE); + char *total = (char *)taosMemoryCalloc(1, MAX_COMMAND_SIZE); memset(cmd->command + cmd->commandSize, 0, MAX_COMMAND_SIZE - cmd->commandSize); sprintf(total, "%s%s", cmd->buffer, cmd->command); @@ -238,20 +238,20 @@ int isReadyGo(Command *cmd) { "(^.*;\\s*$)|(^\\s*$)|(^\\s*exit\\s*$)|(^\\s*q\\s*$)|(^\\s*quit\\s*$)|(^" "\\s*clear\\s*$)"; if (regex_match(total, reg_str, REG_EXTENDED | REG_ICASE)) { - free(total); + taosMemoryFree(total); return 1; } - free(total); + taosMemoryFree(total); return 0; } void getMbSizeInfo(const char *str, int *size, int *width) { - TdWchar *wc = (TdWchar *)calloc(sizeof(TdWchar), MAX_COMMAND_SIZE); + TdWchar *wc = (TdWchar *)taosMemoryCalloc(sizeof(TdWchar), MAX_COMMAND_SIZE); *size = strlen(str); taosMbsToWchars(wc, str, MAX_COMMAND_SIZE); *width = taosWcharsWidth(wc, MAX_COMMAND_SIZE); - free(wc); + taosMemoryFree(wc); } void resetCommand(Command *cmd, const char s[]) { diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 1b35afb57d..0de663f279 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -210,7 +210,7 @@ int32_t shellRunCommand(TAOS *con, char *command) { history.hist[(history.hend + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE] == NULL || strcmp(command, history.hist[(history.hend + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE]) != 0) { if (history.hist[history.hend] != NULL) { - tfree(history.hist[history.hend]); + taosMemoryFreeClear(history.hist[history.hend]); } history.hist[history.hend] = strdup(command); @@ -925,7 +925,7 @@ void read_history() { } } - if(line != NULL) free(line); + if(line != NULL) taosMemoryFree(line); taosCloseFile(&pFile); } @@ -945,7 +945,7 @@ void write_history() { for (int i = history.hstart; i != history.hend;) { if (history.hist[i] != NULL) { taosFprintfFile(pFile, "%s\n", history.hist[i]); - tfree(history.hist[i]); + taosMemoryFreeClear(history.hist[i]); } i = (i + 1) % MAX_HISTORY_SIZE; } @@ -968,13 +968,13 @@ int isCommentLine(char *line) { void source_file(TAOS *con, char *fptr) { wordexp_t full_path; int read_len = 0; - char *cmd = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN + 1); + char *cmd = taosMemoryCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN + 1); size_t cmd_len = 0; char *line = NULL; if (wordexp(fptr, &full_path, 0) != 0) { fprintf(stderr, "ERROR: illegal file name\n"); - free(cmd); + taosMemoryFree(cmd); return; } @@ -985,7 +985,7 @@ void source_file(TAOS *con, char *fptr) { fprintf(stderr, "ERROR: file %s is not exist\n", fptr); wordfree(&full_path); - free(cmd); + taosMemoryFree(cmd); return; } */ @@ -995,7 +995,7 @@ void source_file(TAOS *con, char *fptr) { if (pFile == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); wordfree(&full_path); - free(cmd); + taosMemoryFree(cmd); return; } @@ -1021,8 +1021,8 @@ void source_file(TAOS *con, char *fptr) { cmd_len = 0; } - free(cmd); - if(line != NULL) free(line); + taosMemoryFree(cmd); + if(line != NULL) taosMemoryFree(line); wordfree(&full_path); taosCloseFile(&pFile); } diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c index cc87c2c54b..70563c79e6 100644 --- a/tools/shell/src/shellMain.c +++ b/tools/shell/src/shellMain.c @@ -240,8 +240,8 @@ int32_t shellReadCommand(TAOS *con, char *command) { char utf8_array[10] = "\0"; Command cmd; memset(&cmd, 0, sizeof(cmd)); - cmd.buffer = (char *)calloc(1, MAX_COMMAND_SIZE); - cmd.command = (char *)calloc(1, MAX_COMMAND_SIZE); + cmd.buffer = (char *)taosMemoryCalloc(1, MAX_COMMAND_SIZE); + cmd.command = (char *)taosMemoryCalloc(1, MAX_COMMAND_SIZE); showOnScreen(&cmd); // Read input. @@ -290,8 +290,8 @@ int32_t shellReadCommand(TAOS *con, char *command) { printf("\n"); if (isReadyGo(&cmd)) { sprintf(command, "%s%s", cmd.buffer, cmd.command); - tfree(cmd.buffer); - tfree(cmd.command); + taosMemoryFreeClear(cmd.buffer); + taosMemoryFreeClear(cmd.command); return 0; } else { updateBuffer(&cmd); @@ -405,7 +405,7 @@ void *shellLoopQuery(void *arg) { taosThreadCleanupPush(cleanup_handler, NULL); - char *command = malloc(MAX_COMMAND_SIZE); + char *command = taosMemoryMalloc(MAX_COMMAND_SIZE); if (command == NULL){ uError("failed to malloc command"); return NULL; @@ -424,7 +424,7 @@ void *shellLoopQuery(void *arg) { resetTerminalMode(); } while (shellRunCommand(con, command) == 0); - tfree(command); + taosMemoryFreeClear(command); exitShell(); taosThreadCleanupPop(1); @@ -467,7 +467,7 @@ void showOnScreen(Command *cmd) { int size = 0; // Print out the command. - char *total_string = malloc(MAX_COMMAND_SIZE); + char *total_string = taosMemoryMalloc(MAX_COMMAND_SIZE); memset(total_string, '\0', MAX_COMMAND_SIZE); if (strcmp(cmd->buffer, "") == 0) { sprintf(total_string, "%s%s", PROMPT_HEADER, cmd->command); @@ -499,7 +499,7 @@ void showOnScreen(Command *cmd) { str = total_string + size; } - free(total_string); + taosMemoryFree(total_string); /* for (int i = 0; i < size; i++){ */ /* char c = total_string[i]; */ /* if (k % w.ws_col == 0) { */ diff --git a/tools/shell/src/tnettest.c b/tools/shell/src/tnettest.c index cca7d8b250..9be3412256 100644 --- a/tools/shell/src/tnettest.c +++ b/tools/shell/src/tnettest.c @@ -73,7 +73,7 @@ static void *taosNetBindUdpPort(void *sarg) { return NULL; } - TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); if (pSocket == NULL) { taosCloseSocketNoCheck1(serverSocket); return NULL; @@ -142,7 +142,7 @@ static void *taosNetBindTcpPort(void *sarg) { server_addr.sin_addr.s_addr = htonl(INADDR_ANY); int32_t reuse = 1; - TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); if (pSocket == NULL) { taosCloseSocketNoCheck1(serverSocket); return NULL; @@ -216,7 +216,7 @@ static int32_t taosNetCheckTcpPort(STestInfo *info) { } int32_t reuse = 1; - TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); if (pSocket == NULL) { taosCloseSocketNoCheck1(clientSocket); return -1; @@ -278,7 +278,7 @@ static int32_t taosNetCheckUdpPort(STestInfo *info) { return -1; } - TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + TdSocketPtr pSocket = (TdSocketPtr)taosMemoryMalloc(sizeof(TdSocket)); if (pSocket == NULL) { taosCloseSocketNoCheck1(clientSocket); return -1; @@ -440,7 +440,7 @@ static int32_t taosNetParseStartup(SStartupReq *pCont) { static void taosNetTestStartup(char *host, int32_t port) { uInfo("check startup, host:%s port:%d\n", host, port); - SStartupReq *pStep = malloc(sizeof(SStartupReq)); + SStartupReq *pStep = taosMemoryMalloc(sizeof(SStartupReq)); while (1) { int32_t code = taosNetCheckRpc(host, port, 20, 0, pStep); if (code > 0) { @@ -457,7 +457,7 @@ static void taosNetTestStartup(char *host, int32_t port) { } } - free(pStep); + taosMemoryFree(pStep); } static void taosNetCheckSync(char *host, int32_t port) { @@ -557,9 +557,9 @@ static void taosNetTestServer(char *host, int32_t startPort, int32_t pkgLen) { int32_t num = 1; if (num < 0) num = 1; - TdThread *pids = malloc(2 * num * sizeof(TdThread)); - STestInfo *tinfos = malloc(num * sizeof(STestInfo)); - STestInfo *uinfos = malloc(num * sizeof(STestInfo)); + TdThread *pids = taosMemoryMalloc(2 * num * sizeof(TdThread)); + STestInfo *tinfos = taosMemoryMalloc(num * sizeof(STestInfo)); + STestInfo *uinfos = taosMemoryMalloc(num * sizeof(STestInfo)); for (int32_t i = 0; i < num; i++) { STestInfo *tcpInfo = tinfos + i;