我正在使用ASAN地址消毒剂来检测内存问题。当程序停止时,ASAN抱怨如下:
==102121==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 537 byte(s) in 1 object(s) allocated from:
#0 0x75cb48 in operator new(unsigned long) (/home/app+0x75cb48)
#1 0x7dca83 in __gnu_cxx::new_allocator<char>::allocate(unsigned long, void const*) /opt/rh/devtoolset-7/root/usr/include/c++/7/ext/new_allocator.h:111
#2 0x7ce766 in std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.tcc:1057
#3 0x7cc54d in std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned long) (/home/app+0x7cc54d)
#4 0x7c1f2a in std::string::reserve(unsigned long) /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.tcc:960
#5 0x7fa0a639c6f5 in std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::overflow(int) (/lib64/libstdc++.so.6+0x9b6f5)
Direct leak of 24 byte(s) in 1 object(s) allocated from:
#0 0x75cec8 in operator new(unsigned long, std::nothrow_t const&) (/home/app+0x75cec8)
#1 0x7fa0a635df1d in __cxa_thread_atexit (/lib64/libstdc++.so.6+0x5cf1d)
Indirect leak of 24 byte(s) in 1 object(s) allocated from:
#0 0x75cec8 in operator new(unsigned long, std::nothrow_t const&) (/home/app+0x75cec8)
#1 0x7fa0a635df1d in __cxa_thread_atexit (/lib64/libstdc++.so.6+0x5cf1d)我在ASAN页面上看到,它可以来自于标准库是静态链接的事实。虽然,在我的例子中,它是动态的。
该应用程序是在RHEL上用devtoolset-7编译的。
你知道泄漏是从哪里来的吗?
发布于 2020-10-23 09:45:50
你可以得到比
运算符
# 0x75cb48 (无符号长) (/home/app+0x75cb48)
通过使用llvm象征符。
下载它,并设置环境变量
ASAN_SYMBOLIZER_PATH=/usr/where/ever/the/binary/is如果您确信泄漏是错误警报,则可以使用抑制文件:
创建抑制文本文件并添加到其中的leak: __cxa_thread_atexit:
LSAN_OPTIONS=suppressions=path/to/suppr.txt
然后运行你的应用程序。
http://clang.llvm.org/docs/AddressSanitizer.html#symbolizing-the-reports
https://stackoverflow.com/questions/64497326
复制相似问题