[TD-13756]<fix>: file close memory error.
This commit is contained in:
parent
b06db715bc
commit
5d750f26aa
|
@ -32,6 +32,7 @@ extern "C" {
|
|||
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);
|
||||
int32_t taosMemorySize(void *ptr);
|
||||
|
||||
|
|
|
@ -294,7 +294,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
|
|||
#if FILE_WITH_LOCK
|
||||
taosThreadRwlockWrlock(&((*ppFile)->rwlock));
|
||||
#endif
|
||||
if (ppFile == NULL || *ppFile == NULL || (*ppFile)->fd == -1) {
|
||||
if (ppFile == NULL || *ppFile == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if ((*ppFile)->fp != NULL) {
|
||||
|
|
|
@ -23,15 +23,22 @@
|
|||
|
||||
#define TD_MEMORY_STACK_TRACE_DEPTH 10
|
||||
|
||||
typedef struct TdMemoryInfo *TdMemoryInfoPtr;
|
||||
|
||||
typedef struct TdMemoryInfo {
|
||||
int32_t symbol;
|
||||
int32_t memorySize;
|
||||
void *stackTrace[TD_MEMORY_STACK_TRACE_DEPTH]; // gdb: disassemble /m 0xXXX
|
||||
} *TdMemoryInfoPtr , TdMemoryInfo;
|
||||
// TdMemoryInfoPtr pNext;
|
||||
// TdMemoryInfoPtr pPrev;
|
||||
} TdMemoryInfo;
|
||||
|
||||
// static TdMemoryInfoPtr GlobalMemoryPtr = NULL;
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
|
||||
#define tstrdup(str) _strdup(str)
|
||||
#else
|
||||
#define tstrdup(str) strdup(str)
|
||||
|
||||
#include<execinfo.h>
|
||||
|
||||
|
@ -129,6 +136,26 @@ void *taosMemoryRealloc(void *ptr, int32_t size) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void *taosMemoryStrDup(void *ptr) {
|
||||
#ifdef USE_TD_MEMORY
|
||||
if (ptr == NULL) return NULL;
|
||||
|
||||
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
|
||||
assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL);
|
||||
|
||||
void *tmp = tstrdup((const char *)pTdMemoryInfo);
|
||||
if (tmp == NULL) return NULL;
|
||||
|
||||
memcpy(tmp, pTdMemoryInfo, sizeof(TdMemoryInfo));
|
||||
taosBackTrace(((TdMemoryInfoPtr)tmp)->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH);
|
||||
|
||||
return (char*)tmp + sizeof(TdMemoryInfo);
|
||||
#else
|
||||
return tstrdup((const char *)ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void taosMemoryFree(const void *ptr) {
|
||||
if (ptr == NULL) return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue