2 回答

TA贡献1911条经验 获得超7个赞
我已经通过__lsan_do_leak_check()
在进程退出时显式调用来解决它。
__lsan_do_leak_check() 在
https://github.com/llvm/llvm-project/blob/master/compiler-rt/include/sanitizer/lsan_interface.h
我猜它与 c-main 启动机制有关,并且 __lsan_do_leak_check() 没有为 golang 启动注册。
欢迎任何可以持续挖掘它的人。

TA贡献1829条经验 获得超7个赞
如果您的主程序是用 Go 编写的,您需要手动调用 __lsan_do_leak_check。如果您的 main 是 C/C++ 并且 Go 作为库调用,则不需要它。
这是一个简单的例子
package main
// #include <stdio.h>
// #include <stdlib.h>
//
// void __lsan_do_leak_check(void);
//
// void leak_a_bit(void)
// {
// char* p = malloc(2000);
// printf("%p\n", p);
// }
import "C"
func main() {
C.leak_a_bit()
C.__lsan_do_leak_check()
}
像这样编译运行
$ CC=clang CGO_ENABLED=1 CGO_LDFLAGS='-fsanitize=address' CGO_CFLAGS='-fsanitize=address' go build -o main
$ ./main
- 2 回答
- 0 关注
- 233 浏览
添加回答
举报