如果我编译这个 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).
这是误报吗?
我知道在 Qt Creator 中我们可以添加CONFIG += sanitizer sanitize_address
in the .pro
要启用的文件消毒剂我使用一个主窗口在一个简单的模板项目中进行测试。我在 Qt 5.15.2 中测试它,发现内存泄漏错误。
但当我测试它时Qt_6_2_3
它工作正常。
所以我认为这与 Qt 5 版本有关,他们在 Qt 6 中修复了它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)