提交 040e4354 编写于 作者: D dapan1121

add more free

上级 ce27353c
......@@ -97,7 +97,7 @@ int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) {
void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder) {
if (pBuilder) {
tfree(pBuilder->columns);
TDMFREE(pBuilder->columns);
}
}
......@@ -187,7 +187,7 @@ SDataRow tdNewDataRowFromSchema(STSchema *pSchema) {
* Free the SDataRow object
*/
void tdFreeDataRow(SDataRow row) {
if (row) free(row);
if (row) TDMFREE(row);
}
SDataRow tdDataRowDup(SDataRow row) {
......@@ -339,9 +339,9 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
void tdFreeDataCols(SDataCols *pCols) {
if (pCols) {
tfree(pCols->buf);
tfree(pCols->cols);
free(pCols);
TDMFREE(pCols->buf);
TDMFREE(pCols->cols);
TDMFREE(pCols);
}
}
......@@ -582,7 +582,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
}
*orow = nrow;
free(row);
TDMFREE(row);
} else {
ASSERT(((SColIdx *)ptr)->colId == colId);
if (IS_VAR_DATA_TYPE(type)) {
......@@ -627,7 +627,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
}
*orow = nrow;
free(row);
TDMFREE(row);
}
} else {
memcpy(kvRowColVal(row, (SColIdx *)ptr), value, TYPE_BYTES[type]);
......@@ -662,15 +662,15 @@ int tdInitKVRowBuilder(SKVRowBuilder *pBuilder) {
pBuilder->size = 0;
pBuilder->buf = malloc(pBuilder->alloc);
if (pBuilder->buf == NULL) {
free(pBuilder->pColIdx);
TDMFREE(pBuilder->pColIdx);
return -1;
}
return 0;
}
void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder) {
tfree(pBuilder->pColIdx);
tfree(pBuilder->buf);
TDMFREE(pBuilder->pColIdx);
TDMFREE(pBuilder->buf);
}
void tdResetKVRowBuilder(SKVRowBuilder *pBuilder) {
......
......@@ -125,7 +125,7 @@ void tVariantDestroy(tVariant *pVar) {
if (pVar == NULL) return;
if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) {
tfree(pVar->pz);
TDMFREE(pVar->pz);
pVar->nLen = 0;
}
......@@ -134,7 +134,7 @@ void tVariantDestroy(tVariant *pVar) {
size_t num = taosArrayGetSize(pVar->arr);
for(size_t i = 0; i < num; i++) {
void* p = taosArrayGetP(pVar->arr, i);
free(p);
TDMFREE(p);
}
taosArrayDestroy(pVar->arr);
pVar->arr = NULL;
......@@ -406,7 +406,7 @@ static int32_t toBinary(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
}
taosUcs4ToMbs(pVariant->wpz, (int32_t)newSize, pBuf);
free(pVariant->wpz);
TDMFREE(pVariant->wpz);
pBuf[newSize] = 0;
} else {
taosUcs4ToMbs(pVariant->wpz, (int32_t)newSize, *pDest);
......@@ -456,7 +456,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
// free the binary buffer in the first place
if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
free(pVariant->wpz);
TDMFREE(pVariant->wpz);
}
pVariant->wpz = pWStr;
......@@ -515,7 +515,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
if (token.type == TK_NULL) {
if (releaseVariantPtr) {
free(pVariant->pz);
TDMFREE(pVariant->pz);
pVariant->nLen = 0;
}
......@@ -531,7 +531,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
if (token.type == TK_FLOAT) {
double v = strtod(pVariant->pz, &endPtr);
if (releaseVariantPtr) {
free(pVariant->pz);
TDMFREE(pVariant->pz);
pVariant->nLen = 0;
}
......@@ -543,7 +543,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
} else if (token.type == TK_INTEGER) {
int64_t val = strtoll(pVariant->pz, &endPtr, 10);
if (releaseVariantPtr) {
free(pVariant->pz);
TDMFREE(pVariant->pz);
pVariant->nLen = 0;
}
......@@ -569,7 +569,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
if (token.type == TK_FLOAT) {
double v = wcstod(pVariant->wpz, &endPtr);
if (releaseVariantPtr) {
free(pVariant->pz);
TDMFREE(pVariant->pz);
pVariant->nLen = 0;
}
......@@ -580,7 +580,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
*result = (int64_t)v;
} else if (token.type == TK_NULL) {
if (releaseVariantPtr) {
free(pVariant->pz);
TDMFREE(pVariant->pz);
pVariant->nLen = 0;
}
setNull((char *)result, type, tDataTypeDesc[type].nSize);
......@@ -588,7 +588,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
} else {
int64_t val = wcstoll(pVariant->wpz, &endPtr, 10);
if (releaseVariantPtr) {
free(pVariant->pz);
TDMFREE(pVariant->pz);
pVariant->nLen = 0;
}
......@@ -869,21 +869,21 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) {
errno = 0;
double v = strtod(pVariant->pz, NULL);
if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) {
free(pVariant->pz);
TDMFREE(pVariant->pz);
return -1;
}
free(pVariant->pz);
TDMFREE(pVariant->pz);
pVariant->dKey = v;
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
errno = 0;
double v = wcstod(pVariant->wpz, NULL);
if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) {
free(pVariant->pz);
TDMFREE(pVariant->pz);
return -1;
}
free(pVariant->pz);
TDMFREE(pVariant->pz);
pVariant->dKey = v;
} else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
pVariant->dKey = (double)(pVariant->i64Key);
......
......@@ -22,7 +22,7 @@
#define DO_FREE_HASH_NODE(_n) \
do { \
tfree(_n); \
TDMFREE(_n); \
} while (0)
#define FREE_HASH_NODE(_h, _n) \
......@@ -514,13 +514,13 @@ void taosHashCleanup(SHashObj *pHashObj) {
}
taosHashEmpty(pHashObj);
tfree(pHashObj->hashList);
TDMFREE(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);
TDMFREE(p);
}
taosArrayDestroy(pHashObj->pMemBlock);
......
......@@ -153,7 +153,7 @@ static void tqsortImpl(void *src, int32_t start, int32_t end, size_t size, const
void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ext_compar_fn_t comparFn) {
char *buf = calloc(1, size); // prepare the swap buffer
tqsortImpl(src, 0, (int32_t)numOfElem - 1, (int32_t)size, param, comparFn, buf);
tfree(buf);
TDMFREE(buf);
}
void * taosbsearch(const void *key, const void *base, size_t nmemb, size_t size, __compar_fn_t compar, int flags) {
......
......@@ -29,7 +29,7 @@ void* taosArrayInit(size_t size, size_t elemSize) {
pArray->pData = calloc(size, elemSize);
if (pArray->pData == NULL) {
free(pArray);
TDMFREE(pArray);
return NULL;
}
......@@ -189,8 +189,8 @@ void taosArrayDestroy(SArray* pArray) {
return;
}
free(pArray->pData);
free(pArray);
TDMFREE(pArray->pData);
TDMFREE(pArray);
}
void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*)) {
......
......@@ -104,7 +104,7 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheDataNo
pCacheObj->freeFp(pNode->data);
}
free(pNode);
TDMFREE(pNode);
}
static FORCE_INLINE STrashElem* doRemoveElemInTrashcan(SCacheObj* pCacheObj, STrashElem *pElem) {
......@@ -138,8 +138,8 @@ static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj* pCacheObj, STrashElem
pCacheObj->freeFp(pElem->pData->data);
}
free(pElem->pData);
free(pElem);
TDMFREE(pElem->pData);
TDMFREE(pElem);
}
/**
......@@ -168,7 +168,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
pCacheObj->pHashTable = taosHashInit(4096, taosGetDefaultHashFunction(keyType), false, HASH_ENTRY_LOCK);
pCacheObj->name = strdup(cacheName);
if (pCacheObj->pHashTable == NULL) {
free(pCacheObj);
TDMFREE(pCacheObj);
uError("failed to allocate memory, reason:%s", strerror(errno));
return NULL;
}
......@@ -180,7 +180,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
if (__cache_lock_init(pCacheObj) != 0) {
taosHashCleanup(pCacheObj->pHashTable);
free(pCacheObj);
TDMFREE(pCacheObj);
uError("failed to init lock, reason:%s", strerror(errno));
return NULL;
......@@ -228,7 +228,7 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v
pCacheObj->freeFp(p->data);
}
tfree(p);
TDMFREE(p);
} else {
taosAddToTrashcan(pCacheObj, p);
uDebug("cache:%s, key:%p, %p exist in cache, updated old:%p", pCacheObj->name, key, pNode1->data, p->data);
......@@ -436,7 +436,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
pCacheObj->freeFp(pNode->data);
}
free(pNode);
TDMFREE(pNode);
}
}
} else {
......@@ -615,9 +615,9 @@ void doCleanupDataCache(SCacheObj *pCacheObj) {
__cache_lock_destroy(pCacheObj);
tfree(pCacheObj->name);
TDMFREE(pCacheObj->name);
memset(pCacheObj, 0, sizeof(SCacheObj));
free(pCacheObj);
TDMFREE(pCacheObj);
}
bool travHashTableFn(void* param, void* data) {
......
......@@ -226,7 +226,7 @@ static int32_t compareStrPatternComp(const void* pLeft, const void* pRight) {
buf[sz] = 0;
int32_t ret = patternMatch(pattern, buf, sz, &pInfo);
free(buf);
TDMFREE(buf);
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
}
......
......@@ -317,7 +317,7 @@ void taosReadGlobalLogCfg() {
taosReadLogOption(option, value);
}
tfree(line);
TDMFREE(line);
fclose(fp);
}
......@@ -369,7 +369,7 @@ bool taosReadGlobalCfg() {
fclose(fp);
tfree(line);
TDMFREE(line);
if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
taosSetAllDebugFlag();
......
......@@ -58,7 +58,7 @@ char* taosDesDecode(int64_t key, char* src, int len) {
len += 8;
char* decode = taosDesImp(keyStr, temp, len, DECRYPTION_MODE);
free(temp);
TDMFREE(temp);
return decode;
}
......
......@@ -31,7 +31,7 @@ void *taosInitIdPool(int maxId) {
pIdPool->freeList = calloc(maxId, sizeof(bool));
if (pIdPool->freeList == NULL) {
free(pIdPool);
TDMFREE(pIdPool);
return NULL;
}
......@@ -93,13 +93,13 @@ void taosIdPoolCleanUp(void *handle) {
uDebug("pool:%p is cleaned", pIdPool);
if (pIdPool->freeList) free(pIdPool->freeList);
if (pIdPool->freeList) TDMFREE(pIdPool->freeList);
pthread_mutex_destroy(&pIdPool->mutex);
memset(pIdPool, 0, sizeof(id_pool_t));
free(pIdPool);
TDMFREE(pIdPool);
}
int taosIdPoolNumOfUsed(void *handle) {
......@@ -139,7 +139,7 @@ int taosUpdateIdPool(id_pool_t *handle, int maxId) {
bool *oldIdList = pIdPool->freeList;
pIdPool->freeList = idList;
free(oldIdList);
TDMFREE(oldIdList);
pthread_mutex_unlock(&pIdPool->mutex);
......
......@@ -477,11 +477,11 @@ _err:
static void tdFreeKVStore(SKVStore *pStore) {
if (pStore) {
tfree(pStore->fname);
tfree(pStore->fsnap);
tfree(pStore->fnew);
TDMFREE(pStore->fname);
TDMFREE(pStore->fsnap);
TDMFREE(pStore->fnew);
taosHashCleanup(pStore->map);
free(pStore);
TDMFREE(pStore);
}
}
......@@ -611,11 +611,11 @@ static int tdRestoreKVStore(SKVStore *pStore) {
if (pStore->aFunc) (*pStore->aFunc)(pStore->appH);
tfree(buf);
TDMFREE(buf);
return 0;
_err:
taosHashCancelIterate(pStore->map, pRecord);
tfree(buf);
TDMFREE(buf);
return -1;
}
......@@ -513,8 +513,8 @@ static SLogBuff *taosLogBuffNew(int32_t bufSize) {
return tLogBuff;
_err:
tfree(LOG_BUF_BUFFER(tLogBuff));
tfree(tLogBuff);
TDMFREE(LOG_BUF_BUFFER(tLogBuff));
TDMFREE(tLogBuff);
return NULL;
}
......
......@@ -52,9 +52,9 @@ mpool_h taosMemPoolInit(int numOfBlock, int blockSize) {
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);
TDMFREE(pool_p->freeList);
TDMFREE(pool_p->pool);
TDMFREE(pool_p);
return NULL;
}
......@@ -120,8 +120,8 @@ void taosMemPoolCleanUp(mpool_h handle) {
pool_t *pool_p = (pool_t *)handle;
pthread_mutex_destroy(&pool_p->mutex);
if (pool_p->pool) free(pool_p->pool);
if (pool_p->freeList) free(pool_p->freeList);
if (pool_p->pool) TDMFREE(pool_p->pool);
if (pool_p->freeList) TDMFREE(pool_p->freeList);
memset(pool_p, 0, sizeof(*pool_p));
free(pool_p);
TDMFREE(pool_p);
}
......@@ -406,7 +406,7 @@ static void taosNetTestStartup(char *host, int32_t port) {
}
}
free(pStep);
TDMFREE(pStep);
}
static void taosNetTestRpc(char *host, int32_t startPort, int32_t pkgLen) {
......
......@@ -82,11 +82,11 @@ void taosCloseQueue(taos_queue param) {
while (pNode) {
pTemp = pNode;
pNode = pNode->next;
free (pTemp);
TDMFREE (pTemp);
}
pthread_mutex_destroy(&queue->mutex);
free(queue);
TDMFREE(queue);
uTrace("queue:%p is closed", queue);
}
......@@ -105,7 +105,7 @@ void taosFreeQitem(void *param) {
char *temp = (char *)param;
temp -= sizeof(STaosQnode);
uTrace("item:%p, node:%p is freed", param, temp);
free(temp);
TDMFREE(temp);
}
int taosWriteQitem(taos_queue param, int type, void *item) {
......@@ -166,7 +166,7 @@ void *taosAllocateQall() {
}
void taosFreeQall(void *param) {
free(param);
TDMFREE(param);
}
int taosReadAllQitems(taos_queue param, taos_qall p2) {
......@@ -251,7 +251,7 @@ void taosCloseQset(taos_qset param) {
pthread_mutex_destroy(&qset->mutex);
tsem_destroy(&qset->sem);
free(qset);
TDMFREE(qset);
uTrace("qset:%p is closed", qset);
}
......
......@@ -73,7 +73,7 @@ int taosOpenRef(int max, void (*fp)(void *))
lockedBy = calloc(sizeof(int64_t), (size_t)max);
if (lockedBy == NULL) {
free(nodeList);
TDMFREE(nodeList);
terrno = TSDB_CODE_REF_NO_MEMORY;
return -1;
}
......@@ -102,8 +102,8 @@ int taosOpenRef(int 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);
TDMFREE (nodeList);
TDMFREE (lockedBy);
uTrace("run out of Ref ID, maximum:%d refSetNum:%d", TSDB_REF_OBJECTS, tsRefSetNum);
}
......@@ -438,7 +438,7 @@ static int taosDecRefCount(int rsetId, int64_t rid, int remove) {
if (released) {
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);
TDMFREE(pNode);
taosDecRsetCount(pSet);
}
......@@ -485,8 +485,8 @@ static void taosDecRsetCount(SRefSet *pSet) {
pSet->max = 0;
pSet->fp = NULL;
tfree(pSet->nodeList);
tfree(pSet->lockedBy);
TDMFREE(pSet->nodeList);
TDMFREE(pSet->lockedBy);
tsRefSetNum--;
uTrace("rsetId:%d is cleaned, refSetNum:%d count:%d", pSet->rsetId, tsRefSetNum, pSet->count);
......
......@@ -201,9 +201,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) TDMFREE(pSched->queue);
if (pSched->qthread) TDMFREE(pSched->qthread);
TDMFREE(pSched); // fix memory leak
}
// for debug purpose, dump the scheduler status every 1min.
......
......@@ -27,7 +27,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) TDMFREE((n))
static SSkipListNode *tSkipListPutImpl(SSkipList *pSkipList, void *pData, SSkipListNode **direction, bool isForward,
bool hasDup);
......@@ -99,12 +99,12 @@ void tSkipListDestroy(SSkipList *pSkipList) {
tSkipListUnlock(pSkipList);
if (pSkipList->lock != NULL) {
pthread_rwlock_destroy(pSkipList->lock);
tfree(pSkipList->lock);
TDMFREE(pSkipList->lock);
}
tSkipListFreeNode(pSkipList->pHead);
tSkipListFreeNode(pSkipList->pTail);
tfree(pSkipList);
TDMFREE(pSkipList);
}
SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData) {
......@@ -332,7 +332,7 @@ void *tSkipListDestroyIter(SSkipListIterator *iter) {
return NULL;
}
tfree(iter);
TDMFREE(iter);
return NULL;
}
......
......@@ -38,7 +38,7 @@ char* taosStringBuilderGetResult(SStringBuilder* sb, size_t* len) {
}
void taosStringBuilderDestroy(SStringBuilder* sb) {
free(sb->buf);
TDMFREE(sb->buf);
sb->buf = NULL;
sb->pos = 0;
sb->size = 0;
......
......@@ -114,7 +114,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);
TDMFREE(timer);
}
}
......@@ -575,7 +575,7 @@ void taosTmrCleanUp(void* handle) {
for (int i = 0; i < tListLen(wheels); i++) {
time_wheel_t* wheel = wheels + i;
pthread_mutex_destroy(&wheel->mutex);
free(wheel->slots);
TDMFREE(wheel->slots);
}
pthread_mutex_destroy(&tmrCtrlMutex);
......@@ -585,12 +585,12 @@ void taosTmrCleanUp(void* handle) {
tmr_obj_t* t = list->timers;
while (t != NULL) {
tmr_obj_t* next = t->mnext;
free(t);
TDMFREE(t);
t = next;
}
}
free(timerMap.slots);
free(tmrCtrls);
TDMFREE(timerMap.slots);
TDMFREE(tmrCtrls);
tmrDebug("timer module is cleaned up");
}
......
......@@ -48,7 +48,7 @@ void tWorkerCleanup(SWorkerPool *pPool) {
}
}
free(pPool->worker);
TDMFREE(pPool->worker);
taosCloseQset(pPool->qset);
pthread_mutex_destroy(&pPool->mutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册