解释C ++ / SDL2程序的valgrind输出

时间:2015-04-18 14:48:25

标签: c++ valgrind sdl-2

嗨,有人可以解释一下这个valgrind输出意味着什么,我应该如何解决这个问题?我当前发布的输出是实际终端输出的一部分。其余的也是类似的,大多数都列出了相同的错误。

这适用于使用SDL2的C ++程序。

相关代码非常长,所以我会在评论中添加任何内容。

是否由于某些SDL_Surface * s而发生这种情况?但是我确保在从main()返回之前释放所有这些。另外,我的SDL_Window *是全球性的。这会导致问题。

此输出导致仅在Ubuntu中出现的段错误,而不是在Mac OSX中出现!我知道MAC上的Xcode初始化未初始化的变量并继续进行但在Ubuntu中同样没有发生。但是,即使在memcheck工具中使用trace-origin = yes,valgrind输出也不会显示任何uninit变量。

另外,我没有任何名为call_init or_dl_init或dl_open_worker的函数!!

==17744== 402 bytes in 7 blocks are possibly lost in loss record 506 of 630
==17744==    at 0x4C2CC90: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==17744==    by 0xD3A56A1: ??? (in /usr/lib/x86_64-linux-gnu/dri/i965_dri.so)
==17744==    by 0xD3A5944: ??? (in /usr/lib/x86_64-linux-gnu/dri/i965_dri.so)
==17744==    by 0xD3965C5: ??? (in /usr/lib/x86_64-linux-gnu/dri/i965_dri.so)
==17744==    by 0xD152EAF: ??? (in /usr/lib/x86_64-linux-gnu/dri/i965_dri.so)
==17744==    by 0x4010139: call_init.part.0 (dl-init.c:78)
==17744==    by 0x4010222: call_init (dl-init.c:36)
==17744==    by 0x4010222: _dl_init (dl-init.c:126)
==17744==    by 0x4014C6D: dl_open_worker (dl-open.c:577)
==17744==    by 0x400FFF3: _dl_catch_error (dl-error.c:187)
==17744==    by 0x40143AA: _dl_open (dl-open.c:661)
==17744==    by 0x601E02A: dlopen_doit (dlopen.c:66)
==17744==    by 0x400FFF3: _dl_catch_error (dl-error.c:187)
==17744== 512 bytes in 1 blocks are possibly lost in loss record 519 of 630
==17744==    at 0x4C2CC90: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==17744==    by 0xD3D3689: ??? (in /usr/lib/x86_64-linux-gnu/dri/i965_dri.so)
==17744==    by 0xD412E86: ??? (in /usr/lib/x86_64-linux-gnu/dri/i965_dri.so)
==17744==    by 0xD3D1288: ??? (in /usr/lib/x86_64-linux-gnu/dri/i965_dri.so)
==17744==    by 0xB198E60: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==17744==    by 0xB16D9D3: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==17744==    by 0xB16A0BA: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==17744==    by 0xB16A932: glXChooseVisual (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==17744==    by 0x4EEDD9E: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==17744==    by 0x4EEDFD0: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==17744==    by 0x4EE2BE5: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==17744==    by 0x4EE477B: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==17744== 

==17744== 
==17744== LEAK SUMMARY:
==17744==    definitely lost: 73,806 bytes in 8 blocks
==17744==    indirectly lost: 0 bytes in 0 blocks
==17744==      possibly lost: 1,962,378 bytes in 4,720 blocks
==17744==    still reachable: 2,908,902 bytes in 5,710 blocks
==17744==         suppressed: 0 bytes in 0 blocks
==17744== Reachable blocks (those to which a pointer was found) are not shown.
==17744== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==17744== 
==17744== For counts of detected and suppressed errors, rerun with: -v
==17744== ERROR SUMMARY: 194 errors from 186 contexts (suppressed: 5 from 1)

1 个答案:

答案 0 :(得分:2)

在不知道程序的情况下,Valgrind输出完全没有意义。例如,您可以选择全局分配内容而不删除它,即使在关闭时也是如此。它没有任何伤害,但Valgrind会警告你泄漏,因为这是正式的。这些都不会导致任何段错误,并且您对输出导致它的解释是非常值得怀疑的。

现在,关于dl_*函数,这些函数来自Linux上的动态加载器,所以很可能你没有引起它们。可能它们是值得忽略的,您可以尝试通过将程序剥离到您确定代码不会导致任何问题的程度来重现。

关于全局,它也无所谓,因为原始指针没有任何析构函数。但是,如果您不释放它所代表的资源,Valgrind会将其报告为错误。