diff --git a/src/connector/go/src/taosSql/utils.go b/src/connector/go/src/taosSql/utils.go
index a5a90059b50f57fab7b2f4e8749947a0af840265..a104322fcc9012ea0370bdbea9b89e6674daabf3 100755
--- a/src/connector/go/src/taosSql/utils.go
+++ b/src/connector/go/src/taosSql/utils.go
@@ -12,15 +12,25 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-
package taosSql
+/*
+#cgo CFLAGS : -I/usr/include
+#include
+#cgo LDFLAGS: -L/usr/lib -ltaos
+void taosSetAllocMode(int mode, const char* path, _Bool autoDump);
+void taosDumpMemoryLeak();
+*/
+import "C"
+
+
import (
"database/sql/driver"
"errors"
"fmt"
"sync/atomic"
"time"
+ "unsafe"
)
// Returns the bool value of the input.
@@ -398,3 +408,15 @@ func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) {
}
+/******************************************************************************
+* Utils for C memory issues debugging *
+******************************************************************************/
+func SetAllocMode(mode int32, path string) {
+ cpath := C.CString(path)
+ defer C.free(unsafe.Pointer(cpath))
+ C.taosSetAllocMode(C.int(mode), cpath, false)
+}
+
+func DumpMemoryLeak() {
+ C.taosDumpMemoryLeak()
+}
diff --git a/src/util/src/tmem.c b/src/util/src/tmem.c
index 5a42933ebe0ff805b5a26ea6a3358d536daf84fe..2625e4e5e6a645c4de2bd97534324b037acb4aaa 100644
--- a/src/util/src/tmem.c
+++ b/src/util/src/tmem.c
@@ -45,7 +45,7 @@ static bool random_alloc_fail(size_t size, const char* file, uint32_t line) {
}
if (fpAllocLog != NULL) {
- fprintf(fpAllocLog, "memory allocation(%zu bytes) at line %d of '%s' will fail.\n", size, line, file);
+ fprintf(fpAllocLog, "%s:%d: memory allocation of %zu bytes will fail.\n", file, line, size);
}
return true;
@@ -137,7 +137,7 @@ static void free_detect_leak(void* ptr, const char* file, uint32_t line) {
SMemBlock* blk = (SMemBlock*)(((char*)ptr) - sizeof(SMemBlock));
if (blk->magic != MEMBLK_MAGIC) {
if (fpAllocLog != NULL) {
- fprintf(fpAllocLog, "%s:%d: memory not allocated by 'taos_malloc'.\n", file, line);
+ fprintf(fpAllocLog, "%s:%d: memory is allocated by default allocator.\n", file, line);
}
free(ptr);
return;
@@ -196,7 +196,7 @@ static void* realloc_detect_leak(void* ptr, size_t size, const char* file, uint3
SMemBlock* blk = ((char*)ptr) - sizeof(SMemBlock);
if (blk->magic != MEMBLK_MAGIC) {
if (fpAllocLog != NULL) {
- fprintf(fpAllocLog, "%s:%d: memory not allocated by 'taos_malloc'.\n", file, line);
+ fprintf(fpAllocLog, "%s:%d: memory is allocated by default allocator.\n", file, line);
}
return realloc(ptr, size);
}
@@ -265,7 +265,7 @@ static ssize_t getline_detect_leak(char **lineptr, size_t *n, FILE *stream, cons
static void dump_memory_leak() {
const char* hex = "0123456789ABCDEF";
- const char* fmt = ":%d: addr=0x%p, size=%d, content(first 16 bytes)=";
+ const char* fmt = ":%d: addr=%p, size=%d, content(first 16 bytes)=";
size_t numOfBlk = 0, totalSize = 0;
if (fpAllocLog == NULL) {