简体   繁体   English

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

[英]Interpreting valgrind output for a C++/SDL2 program

Hi can somebody please explain what this valgrind output means and how I should go about fixing this ?? 嗨,有人可以解释一下valgrind输出的含义,以及如何解决这个问题吗? The output I am posting currently is a part of the actual terminal output. 我当前发布的输出是实际终端输出的一部分。 The rest is also similar and mostly the same errors are listed. 其余的也相似,并且列出了几乎相同的错误。

This is for a C++ program using SDL2. 这是针对使用SDL2的C ++程序。

The relevant code is really long so I will add whatever is asked in comments. 相关代码很长,因此我将添加注释中要求的内容。

Is this happening due to some SDL_Surface* s? 这是由于某些SDL_Surface *导致的吗? But I made sure to free all of those before returning from main(). 但是我确保在从main()返回之前释放所有这些。 Also, my SDL_Window* is global. 另外,我的SDL_Window *是全局的。 Can that cause a problem. 会引起问题吗?

This output leads to a segfault that arises only in Ubuntu and not in Mac OSX!! 此输出导致仅在Ubuntu中而不在Mac OSX中出现的段错误! I know that Xcode on MAC initializes uninitialized variables and proceeds but the same doesnt happen in Ubuntu. 我知道MAC上的Xcode会初始化未初始化的变量并继续执行,但在Ubuntu中不会发生相同的情况。 But the valgrind output doesn't show any uninit variables even with trace-origins = yes in memcheck tool. 但是,即使在memcheck工具中使用trace-origins = yes,valgrind输出也不会显示任何未初始化的变量。

Also, I don't have any functions named call_init or_dl_init or dl_open_worker!! 另外,我没有任何名为call_init或_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)

Without knowing the program, the Valgrind output is completely meaningless. 在不知道程序的情况下,Valgrind输出完全没有意义。 For example, you can choose to allocate something globally and never delete it, not even on shutdown. 例如,您可以选择全局分配某些内容,甚至在关机时也不会删除它。 It doesn't hurt in any way, but Valgrind will warn you about a leak, because that's what it is formally. 它没有任何伤害,但是Valgrind会警告您泄漏,因为这是正式的泄漏。 None of this should cause any segfaults though and your interpretation that the output causes it is very questionable. 但是,这都不应该引起任何段错误,并且您对输出导致它的解释非常可疑。

Now, concerning the dl_* functions, those are from the dynamic loader on Linux, so chances are that you didn't cause them. 现在,关于dl_*函数,这些函数来自Linux上的动态加载程序,因此很可能不是您造成的。 Probably they are something to ignore, which you could try to reproduce by stripping your program down to the point where you are sure that your code doesn't cause any issues. 可能它们是要忽略的东西,您可以尝试通过将程序剥离到可以确保代码不会引起任何问题的程度来重现。

Concerning the global, it doesn't matter either, because a raw pointer doesn't have any destructor. 关于全局,这也没有关系,因为原始指针没有任何析构函数。 However, if you don't release the resource it represents, Valgrind will report that as error. 但是,如果您不释放它所代表的资源,则Valgrind会将其报告为错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM