如果我编译这个QT"Hello world":
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
int main( int argc, char **argv ) {
QApplication a( argc, argv );
QPushButton hello( "Hello world!" );
hello.resize( 100, 30 );
hello.show();
return a.exec();
}
使用GCC 12.2(从源安装)的Debian稳定版(使用系统Qt库)
$ g++ -fsanitize=address hello.cpp -L /usr/lib/x86_64-linux-gnu -lQt5Core -lQt5Gui -lQt5Widgets -I /usr/include/x86_64-linux-gnu/qt5 -fPIC
当我关闭应用程序时,这会导致检测到泄漏:
$ ./a.out
=================================================================
==3563910==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 6656 byte(s) in 26 object(s) allocated from:
#0 0x7fea3b4801af in __interceptor_malloc ../../../../gcc-12.2.0/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7fea3693c704 (/lib/x86_64-linux-gnu/libfontconfig.so.1+0x20704)
Indirect leak of 1600 byte(s) in 50 object(s) allocated from:
#0 0x7fea3b47fb97 in __interceptor_calloc ../../../../gcc-12.2.0/libsanitizer/asan/asan_malloc_linux.cpp:77
#1 0x7fea3693cd48 (/lib/x86_64-linux-gnu/libfontconfig.so.1+0x20d48)
Indirect leak of 519 byte(s) in 50 object(s) allocated from:
#0 0x7fea3b437f3b in __interceptor_strdup ../../../../gcc-12.2.0/libsanitizer/asan/asan_interceptors.cpp:439
#1 0x7fea3693bfa4 in FcValueSave (/lib/x86_64-linux-gnu/libfontconfig.so.1+0x1ffa4)
SUMMARY: AddressSanitizer: 8775 byte(s) leaked in 126 allocation(s).
这是假阳性吗?