有人在使用 valgrind 和 Qt 吗? [英] Is anyone using valgrind and Qt?

查看:46
本文介绍了有人在使用 valgrind 和 Qt 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Qt/C++ 调试大型应用程序构建,而 valgrind 报告来自 Qt 内部内容的大量内存泄漏.任何人都可以为 Qt 应用程序共享适当的 valgrind 抑制文件吗?

谢谢!

例如

#include int main(){QObject o;返回0;}

返回:

<前>$ valgrind --leak-check=full --show-reachable=yes ./leak==12655== Memcheck,内存错误检测器==12655== 版权所有 (C) 2002-2009 和 GNU GPL,由 Julian Seward 等人所有.==12655== 使用 Valgrind-3.5.0-Debian 和 LibVEX;使用 -h 重新运行以获取版权信息==12655== 命令:./leak==12655====12655====12655== 堆摘要:==12655== 退出时使用:7 个块中的 744 个字节==12655== 总堆使用量:28 个分配,21 个释放,1,640 字节分配==12655====12655== 1 个块中的 16 个字节在丢失记录 1 of 7 中仍然可达==12655== 在 0x4C229C7:运算符 new(unsigned long) (vg_replace_malloc.c:220)==12655== 由 0x6203124:QThreadData::current()(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62FC4BC: QObject::QObject(QObject*)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== by 0x4008D2: main (in/tmp/Qt/bin/leak)==12655====12655== 1 个块中的 96 个字节在丢失记录 2 of 7 中仍然可达==12655== 在 0x4C229C7:运算符 new(unsigned long) (vg_replace_malloc.c:220)==12655== 由 0x62030FC: QThreadData::current() (在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62FC4BC: QObject::QObject(QObject*)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== by 0x4008D2: main (in/tmp/Qt/bin/leak)==12655====12655== 1 个块中的 96 个字节在丢失记录 3 of 7 中仍然可达==12655== 在 0x4C229C7:运算符 new(unsigned long) (vg_replace_malloc.c:220)==12655== 由 0x62041CD: QWaitCondition::QWaitCondition() (在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x6200EAF: ???(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62010A0: ???(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x6203132:QThreadData::current()(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62FC4BC: QObject::QObject(QObject*)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== by 0x4008D2: main (in/tmp/Qt/bin/leak)==12655====12655== 1 个块中的 120 个字节在丢失记录 4 of 7 中仍然可以访问==12655== 在 0x4C229C7:运算符 new(unsigned long) (vg_replace_malloc.c:220)==12655== 由 0x61FE681:QMutex::QMutex(QMutex::RecursionMode)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x6200DC8:QThreadData::QThreadData(int)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x620310C:QThreadData::current()(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62FC4BC: QObject::QObject(QObject*)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== by 0x4008D2: main (in/tmp/Qt/bin/leak)==12655====12655== 1 个块中的 120 个字节在丢失记录 5 of 7 中仍然可以访问==12655== 在 0x4C229C7:运算符 new(unsigned long) (vg_replace_malloc.c:220)==12655== 由 0x61FE681:QMutex::QMutex(QMutex::RecursionMode)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x6200DE9:QThreadData::QThreadData(int)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x620310C:QThreadData::current()(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62FC4BC: QObject::QObject(QObject*)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== by 0x4008D2: main (in/tmp/Qt/bin/leak)==12655====12655== 1 个块中的 120 个字节在丢失记录 6 of 7 中仍然可达==12655== 在 0x4C229C7:运算符 new(unsigned long) (vg_replace_malloc.c:220)==12655== 由 0x61FE681:QMutex::QMutex(QMutex::RecursionMode)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x6200E77: ???(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62010A0: ???(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x6203132:QThreadData::current()(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62FC4BC: QObject::QObject(QObject*)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== by 0x4008D2: main (in/tmp/Qt/bin/leak)==12655====12655== 1 个块中的 176 个字节在丢失记录 7 of 7 中仍然可达==12655== 在 0x4C229C7:运算符 new(unsigned long) (vg_replace_malloc.c:220)==12655== 由 0x6201092: ???(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x6203132:QThreadData::current()(在/usr/lib/libQtCore.so.4.5.2 中)==12655== 由 0x62FC4BC: QObject::QObject(QObject*)(在/usr/lib/libQtCore.so.4.5.2 中)==12655== by 0x4008D2: main (in/tmp/Qt/bin/leak)==12655====12655== 泄漏摘要:==12655== 肯定丢失了:0 个块中的 0 个字节==12655== 间接丢失:0 个块中的 0 个字节==12655== 可能丢失:0 个块中的 0 个字节==12655== 仍然可达:7 个块中有 744 个字节==12655== 被抑制:0 个块中的 0 个字节==12655====12655== 对于检测到和抑制的错误的计数,重新运行: -v==12655== 错误摘要:0 个上下文中的 0 个错误(被抑制:8 个中的 8 个)

解决方案

--show-reachable 显示实际上并未泄漏的内存,即使 valgrind 将其称为丢失记录.您的测试应用程序不会泄漏任何内存.

对于这种特殊情况,您不需要任何 valgrind 抑制.对于其他人,也许,但您应该使用 valgrind 的 --gen-suppressions 选项为您生成这些抑制.

I am trying to debug a large application build using Qt/C++ and valgrind is reporting a lot of memory leak from internal Qt stuff. Could anyone share a proper valgrind suppression file for Qt apps ?

Thanks !

Eg.

#include <qobject.h>
int main()
{
  QObject o;
  return 0;
}

returns:

$ valgrind  --leak-check=full  --show-reachable=yes  ./leak
==12655== Memcheck, a memory error detector
==12655== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==12655== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info
==12655== Command: ./leak
==12655== 
==12655== 
==12655== HEAP SUMMARY:
==12655==     in use at exit: 744 bytes in 7 blocks
==12655==   total heap usage: 28 allocs, 21 frees, 1,640 bytes allocated
==12655== 
==12655== 16 bytes in 1 blocks are still reachable in loss record 1 of 7
==12655==    at 0x4C229C7: operator new(unsigned long) (vg_replace_malloc.c:220)
==12655==    by 0x6203124: QThreadData::current() (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62FC4BC: QObject::QObject(QObject*) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x4008D2: main (in /tmp/Qt/bin/leak)
==12655== 
==12655== 96 bytes in 1 blocks are still reachable in loss record 2 of 7
==12655==    at 0x4C229C7: operator new(unsigned long) (vg_replace_malloc.c:220)
==12655==    by 0x62030FC: QThreadData::current() (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62FC4BC: QObject::QObject(QObject*) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x4008D2: main (in /tmp/Qt/bin/leak)
==12655== 
==12655== 96 bytes in 1 blocks are still reachable in loss record 3 of 7
==12655==    at 0x4C229C7: operator new(unsigned long) (vg_replace_malloc.c:220)
==12655==    by 0x62041CD: QWaitCondition::QWaitCondition() (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x6200EAF: ??? (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62010A0: ??? (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x6203132: QThreadData::current() (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62FC4BC: QObject::QObject(QObject*) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x4008D2: main (in /tmp/Qt/bin/leak)
==12655== 
==12655== 120 bytes in 1 blocks are still reachable in loss record 4 of 7
==12655==    at 0x4C229C7: operator new(unsigned long) (vg_replace_malloc.c:220)
==12655==    by 0x61FE681: QMutex::QMutex(QMutex::RecursionMode) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x6200DC8: QThreadData::QThreadData(int) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x620310C: QThreadData::current() (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62FC4BC: QObject::QObject(QObject*) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x4008D2: main (in /tmp/Qt/bin/leak)
==12655== 
==12655== 120 bytes in 1 blocks are still reachable in loss record 5 of 7
==12655==    at 0x4C229C7: operator new(unsigned long) (vg_replace_malloc.c:220)
==12655==    by 0x61FE681: QMutex::QMutex(QMutex::RecursionMode) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x6200DE9: QThreadData::QThreadData(int) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x620310C: QThreadData::current() (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62FC4BC: QObject::QObject(QObject*) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x4008D2: main (in /tmp/Qt/bin/leak)
==12655== 
==12655== 120 bytes in 1 blocks are still reachable in loss record 6 of 7
==12655==    at 0x4C229C7: operator new(unsigned long) (vg_replace_malloc.c:220)
==12655==    by 0x61FE681: QMutex::QMutex(QMutex::RecursionMode) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x6200E77: ??? (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62010A0: ??? (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x6203132: QThreadData::current() (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62FC4BC: QObject::QObject(QObject*) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x4008D2: main (in /tmp/Qt/bin/leak)
==12655== 
==12655== 176 bytes in 1 blocks are still reachable in loss record 7 of 7
==12655==    at 0x4C229C7: operator new(unsigned long) (vg_replace_malloc.c:220)
==12655==    by 0x6201092: ??? (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x6203132: QThreadData::current() (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x62FC4BC: QObject::QObject(QObject*) (in /usr/lib/libQtCore.so.4.5.2)
==12655==    by 0x4008D2: main (in /tmp/Qt/bin/leak)
==12655== 
==12655== LEAK SUMMARY:
==12655==    definitely lost: 0 bytes in 0 blocks
==12655==    indirectly lost: 0 bytes in 0 blocks
==12655==      possibly lost: 0 bytes in 0 blocks
==12655==    still reachable: 744 bytes in 7 blocks
==12655==         suppressed: 0 bytes in 0 blocks
==12655== 
==12655== For counts of detected and suppressed errors, rerun with: -v
==12655== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 8)

解决方案

--show-reachable shows memory that hasn't actually leaked, even though valgrind calls it a loss record. Your test app doesn't leak any memory.

You don't need any valgrind suppressions for this particular case. For others, maybe, but you should use valgrind's --gen-suppressions option to generate those suppressions for you.

这篇关于有人在使用 valgrind 和 Qt 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆