看到我只是使用valgrind来检测代码中的内存泄漏。所以我用过
valgrind -v --leak-check=full --show-reachable=yes ./my_binary
我看到我无法理解的跟进
`==16545==
==16545== HEAP SUMMARY:
==16545== in use at exit: 20,171 bytes in 647 blocks
==16545== total heap usage: 993 allocs, 346 frees, 30,090 bytes allocated
==16545==
==16545== Searching for pointers to 647 not-freed blocks
==16545== Checked 124,548 bytes
==16545==
==16545== 1 bytes in 1 blocks are still reachable in loss record 1 of 253
==16545== at 0x400677E: malloc (vg_replace_malloc.c:195)
==16545== by 0x80AAB31: xmalloc (in /bin/bash)
==16545== by 0x80796D0: make_variable_value (in /bin/bash)
==16545== by 0x80798C8: ??? (in /bin/bash)
==16545== by 0x807BA40: initialize_shell_variables (in /bin/bash)
==16545== by 0x805E897: ??? (in /bin/bash)
==16545== by 0x805FA10: main (in /bin/bash)
==16545==
==16545== 1 bytes in 1 blocks are still reachable in loss record 2 of 253
==16545== at 0x400677E: malloc (vg_replace_malloc.c:195)
==16545== by 0x80AAB31: xmalloc (in /bin/bash)
==16545== by 0x80A578B: set_locale_var (in /bin/bash)
==16545== by 0x80A5912: set_default_lang (in /bin/bash)
==16545== by 0x805FA15: main (in /bin/bash)
==16545==
==16545== 1 bytes in 1 blocks are still reachable in loss record 3 of 253
==16545== at 0x400677E: malloc (vg_replace_malloc.c:195)
==16545== by 0x80AAB31: xmalloc (in /bin/bash)
==16545== by 0x8061B9B: ??? (in /bin/bash)
==16545== by 0x8062D95: ??? (in /bin/bash)
==16545== by 0x8065481: ??? (in /bin/bash)
==16545== by 0x806801A: yyparse (in /bin/bash)
==16545== by 0x8060580: parse_command (in /bin/bash)
==16545== by 0x806064F: read_command (in /bin/bash)
==16545== by 0x80608AE: reader_loop (in /bin/bash)
==16545== by 0x805FEFB: main (in /bin/bash)`e
我只想了解这一点。 为什么这没有给我特定的行代码没有释放?
答案 0 :(得分:4)
这些错误来自/bin/bash
,而不是来自您自己的代码。您是否正在运行代码中的任何bash脚本? Here解释了它的含义。我想你可以忽略它。
“仍然可以访问”意味着你的程序可能没问题 - 它没有免费 它可能有一些记忆。这很常见,而且往往是合理的。 如果您不想看到这些报告,请不要使用--show-reachable = yes。
答案 1 :(得分:1)
看起来这些地址属于您程序的代码。也许使用调试信息进行编译可以让valgrind看到行号。 (提示:-g开启gcc)
答案 2 :(得分:0)
您检查了http://valgrind.org/docs/manual/quick-start.html#quick-start.intro吗?那里有很好的文档。在编译时,您不应该使用任何优化。
答案 3 :(得分:0)
如果要检查autotools驱动的编译结果(它确实在你的构建目录中创建了一个shell脚本),你可能想要尝试这样做:
libtool --mode=execute valgrind -v --leak-check=full --show-reachable=yes ./my_binary