Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
91f5600c
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
91f5600c
编写于
11月 21, 2019
作者:
weixin_48148422
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add memory check to GO connector
also update log format
上级
e7bdf0c2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
5 deletion
+27
-5
src/connector/go/src/taosSql/utils.go
src/connector/go/src/taosSql/utils.go
+23
-1
src/util/src/tmem.c
src/util/src/tmem.c
+4
-4
未找到文件。
src/connector/go/src/taosSql/utils.go
浏览文件 @
91f5600c
...
@@ -12,15 +12,25 @@
...
@@ -12,15 +12,25 @@
* You should have received a copy of the GNU Affero General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
package
taosSql
package
taosSql
/*
#cgo CFLAGS : -I/usr/include
#include <stdlib.h>
#cgo LDFLAGS: -L/usr/lib -ltaos
void taosSetAllocMode(int mode, const char* path, _Bool autoDump);
void taosDumpMemoryLeak();
*/
import
"C"
import
(
import
(
"database/sql/driver"
"database/sql/driver"
"errors"
"errors"
"fmt"
"fmt"
"sync/atomic"
"sync/atomic"
"time"
"time"
"unsafe"
)
)
// Returns the bool value of the input.
// Returns the bool value of the input.
...
@@ -398,3 +408,15 @@ func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) {
...
@@ -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
()
}
src/util/src/tmem.c
浏览文件 @
91f5600c
...
@@ -45,7 +45,7 @@ static bool random_alloc_fail(size_t size, const char* file, uint32_t line) {
...
@@ -45,7 +45,7 @@ static bool random_alloc_fail(size_t size, const char* file, uint32_t line) {
}
}
if
(
fpAllocLog
!=
NULL
)
{
if
(
fpAllocLog
!=
NULL
)
{
fprintf
(
fpAllocLog
,
"
memory allocation(%zu bytes) at line %d of '%s' will fail.
\n
"
,
size
,
line
,
fil
e
);
fprintf
(
fpAllocLog
,
"
%s:%d: memory allocation of %zu bytes will fail.
\n
"
,
file
,
line
,
siz
e
);
}
}
return
true
;
return
true
;
...
@@ -137,7 +137,7 @@ static void free_detect_leak(void* ptr, const char* file, uint32_t line) {
...
@@ -137,7 +137,7 @@ static void free_detect_leak(void* ptr, const char* file, uint32_t line) {
SMemBlock
*
blk
=
(
SMemBlock
*
)(((
char
*
)
ptr
)
-
sizeof
(
SMemBlock
));
SMemBlock
*
blk
=
(
SMemBlock
*
)(((
char
*
)
ptr
)
-
sizeof
(
SMemBlock
));
if
(
blk
->
magic
!=
MEMBLK_MAGIC
)
{
if
(
blk
->
magic
!=
MEMBLK_MAGIC
)
{
if
(
fpAllocLog
!=
NULL
)
{
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
);
free
(
ptr
);
return
;
return
;
...
@@ -196,7 +196,7 @@ static void* realloc_detect_leak(void* ptr, size_t size, const char* file, uint3
...
@@ -196,7 +196,7 @@ static void* realloc_detect_leak(void* ptr, size_t size, const char* file, uint3
SMemBlock
*
blk
=
((
char
*
)
ptr
)
-
sizeof
(
SMemBlock
);
SMemBlock
*
blk
=
((
char
*
)
ptr
)
-
sizeof
(
SMemBlock
);
if
(
blk
->
magic
!=
MEMBLK_MAGIC
)
{
if
(
blk
->
magic
!=
MEMBLK_MAGIC
)
{
if
(
fpAllocLog
!=
NULL
)
{
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
);
return
realloc
(
ptr
,
size
);
}
}
...
@@ -265,7 +265,7 @@ static ssize_t getline_detect_leak(char **lineptr, size_t *n, FILE *stream, cons
...
@@ -265,7 +265,7 @@ static ssize_t getline_detect_leak(char **lineptr, size_t *n, FILE *stream, cons
static
void
dump_memory_leak
()
{
static
void
dump_memory_leak
()
{
const
char
*
hex
=
"0123456789ABCDEF"
;
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
;
size_t
numOfBlk
=
0
,
totalSize
=
0
;
if
(
fpAllocLog
==
NULL
)
{
if
(
fpAllocLog
==
NULL
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录