通过我编译的程序运行 valgrind 时,我得到以下输出片段:
==80341== HEAP SUMMARY:
==80341== in use at exit: 6,840 bytes in 27 blocks
==80341== total heap usage: 107,314 allocs, 107,287 frees, 103,658,505 bytes allocated
==80341==
==80341== 8 bytes in 1 blocks are definitely lost in loss record 1 of 27
==80341== at 0x4843223: operator new[](unsigned long) (vg_replace_malloc.c:714)
==80341== by 0x48A5986: _sub_I_65535_0.0 (commandlineflags.h:132)
==80341== by 0x4004EED: call_init (dl-init.c:90)
==80341== by 0x4004EED: call_init (dl-init.c:27)
==80341== by 0x4004FDB: _dl_init (dl-init.c:137)
==80341== by 0x401B2CF: ??? (in /usr/lib/ld-linux-x86-64.so.2)
==80341== by 0x8: ???
==80341== by 0x1FFF0000C2: ???
==80341== by 0x1FFF0000D8: ???
==80341== by 0x1FFF0000DF: ???
==80341== by 0x1FFF000126: ???
==80341== by 0x1FFF00012E: ???
==80341== by 0x1FFF000147: ???
==80341==
...
==80341== LEAK SUMMARY:
==80341== definitely lost: 8 bytes in 1 blocks
==80341== indirectly lost: 0 bytes in 0 blocks
==80341== possibly lost: 0 bytes in 0 blocks
==80341== still reachable: 6,832 bytes in 26 blocks
==80341== suppressed: 0 bytes in 0 blocks
这条痕迹让我感到困惑。我怀疑这涉及
ld-linux-x86-64.so
,它可能没有调试符号,这就是出现问题的原因。我还有代码的其他部分,valgrind 可以精确定位跟踪(我希望这是一个单独的问题)。
这是来自我的应用程序还是某些 valgrind 工件?运行一些正常的程序可以让我干净地运行,所以我怀疑这是我的程序的一部分。
如何调试这种情况以查明程序的哪一部分导致了这种行为?
重要的是
new
下面的一行:
==80341== by 0x48A5986: _sub_I_65535_0.0 (commandlineflags.h:132)
它可能类似于文件静态,在加载 exe 或共享库时进行初始化。查看上面指示的行,commandlinflags.h 第 132 行。