Merge pull request #11518 from taosdata/fix/ZhiqiangWang/TD-13758-fix-free-func-const-ptr
fix(os): const ptr is passed to free()
This commit is contained in:
commit
68bdc0deae
|
@ -33,13 +33,13 @@ void *taosMemoryMalloc(int32_t size);
|
|||
void *taosMemoryCalloc(int32_t num, int32_t size);
|
||||
void *taosMemoryRealloc(void *ptr, int32_t size);
|
||||
void *taosMemoryStrDup(void *ptr);
|
||||
void taosMemoryFree(const void *ptr);
|
||||
void taosMemoryFree(void *ptr);
|
||||
int32_t taosMemorySize(void *ptr);
|
||||
|
||||
#define taosMemoryFreeClear(ptr) \
|
||||
do { \
|
||||
if (ptr) { \
|
||||
taosMemoryFree(ptr); \
|
||||
taosMemoryFree((void*)ptr); \
|
||||
(ptr) = NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
|
@ -292,7 +292,7 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) {
|
|||
|
||||
void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) {
|
||||
queue->q = taosArrayInit(2, sizeof(void*));
|
||||
queue->freeFunc = freeFunc;
|
||||
queue->freeFunc = (void (*)(const void*))freeFunc;
|
||||
}
|
||||
bool transQueuePush(STransQueue* queue, void* arg) {
|
||||
if (queue->q == NULL) {
|
||||
|
|
|
@ -156,14 +156,14 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
|
@ -176,14 +176,14 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
|
@ -198,7 +198,7 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree};
|
||||
val1.val = taosMemoryCalloc(1, 11);
|
||||
memcpy(val1.val, val.c_str(), val.size());
|
||||
|
||||
|
@ -206,7 +206,7 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = (void (*)(const void*))taosMemoryFree};
|
||||
val1.val = taosMemoryCalloc(1, 11);
|
||||
memcpy(val1.val, val.c_str(), val.size());
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
|
|
|
@ -156,7 +156,7 @@ void *taosMemoryStrDup(void *ptr) {
|
|||
}
|
||||
|
||||
|
||||
void taosMemoryFree(const void *ptr) {
|
||||
void taosMemoryFree(void *ptr) {
|
||||
if (ptr == NULL) return;
|
||||
|
||||
#ifdef USE_TD_MEMORY
|
||||
|
@ -166,10 +166,10 @@ void taosMemoryFree(const void *ptr) {
|
|||
// memset(pTdMemoryInfo, 0, sizeof(TdMemoryInfo));
|
||||
free(pTdMemoryInfo);
|
||||
} else {
|
||||
free((void*)ptr);
|
||||
free(ptr);
|
||||
}
|
||||
#else
|
||||
return free((void*)ptr);
|
||||
return free(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue