如果我编译这个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).

这是假阳性吗?

推荐答案

我了解到,在QtCreator中,我们可以在.pro文件中添加CONFIG += sanitizer sanitize_address,以启用sanitizer和我在一个简单的模板项目中使用一个主窗口进行测试.我在Qt 5.15.2中测试了它,发现了一个内存泄漏错误.

enter image description here

但当我在Qt_6_2_3分钟内测试它时,它工作正常. 所以我认为这与Qt5版本有关,他们在Qt6中修复了它.

enter image description here

Linux相关问答推荐

列出Linux上特定目录和子目录名称的bash命令

C++调试器如何知道如何在源代码和可执行文件之间映射行?

在 bash 中使用 tee 时如何返回错误代码

如何让xargs对 bash 脚本中find命令找到的所有文件执行?

为什么我在从 Linux 通过 telnet 发送 Ctrl-C 后停止接收数据?

有没有办法确定什么代码使 linux 共享对象inflating ?

更改 awk 中的上一个重复行

sed 根据文件中的条件进行多次替换

ENQCMD 指令的好处和微操作是什么?

有没有办法定义自定义隐式 GNU Make 规则?

如何在 Linux 中获取 C/C++ 中的用户名?

anon 对 pmap 意味着什么?

如何指定链接时使用的库版本?

未找到框架.NETFramework,Version=v4.7.1的参考程序集

为什么在编译 K&R2 第 1 章中最长的行示例时出现getline 的类型冲突错误?

yum 可以告诉我哪些存储库提供了特定的包吗?

将参数传递给 awk 脚本文件

如何使用文件描述符刷新写入?

使用 Bash 脚本查找文件中字符串的行号

`os.symlink` 与 `ln -s`