如果我编译这个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();
}
在Debian Stable上(使用系统Qt库),使用从源代码安装的GCC 12.2
$ 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).
这是一个误报吗?
new
创建的小部件不应该被显式地delete
。但这只是一种猜测。 - Red.Wavemain
函数。这意味着静态链接的动态库libfontconfig.so
存在问题。请注意,其他人在不使用 Qt 的情况下也遇到了相同的问题:https://github.com/Raymo111/i3lock-color/issues/88 - Marek R