需要有关 valgrind 输出理解的帮助

发布于 2024-12-01 13:58:15 字数 1918 浏览 0 评论 0原文

看到我只是使用 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

我只是想了解这一点。? 为什么这没有给我ma代码中尚未释放的特定行号?

see i am just using valgrind for detecting memory leakage in my code. so i have used

valgrind -v --leak-check=full --show-reachable=yes  ./my_binary

i see following out which i can not understand

`==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

i just want to understand this.?
why this does not giving me particular line no in ma code which has not freed ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

八巷 2024-12-08 13:58:15

这些错误来自 /bin/bash 而不是您自己的代码。您是否在代码中运行任何 bash 脚本? 这里解释了它的含义。我认为你可以忽略它。

“仍然可达”意味着你的程序可能没问题——它不是免费的
它可能有一些记忆。这是很常见的,而且往往是合理的。
如果您不想看到这些报告,请不要使用 --show-reachable=yes。

These errors come from /bin/bash not from your own code. Are you running any bash scripts from your code? Here is explanation of what it means. I think you can just ignore it.

"still reachable" means your program is probably ok -- it didn't free
some memory it could have. This is quite common and often reasonable.
Don't use --show-reachable=yes if you don't want to see these reports.

世态炎凉 2024-12-08 13:58:15

看起来这些地址属于您的程序代码。也许使用调试信息进行编译可以让 valgrind 看到行号。 (提示:-g 开启 gcc)

It looks like those addresses belong to your program's code. Perhaps compiling with debug information lets valgrind see line numbers. (Hint: -g switch on gcc)

舟遥客 2024-12-08 13:58:15

您检查过 http://valgrind.org/docs/manual/快速启动.html#quick-start.intro ?那里有一个很好的文档。您在编译时不应该使用任何优化。

Have you checked http://valgrind.org/docs/manual/quick-start.html#quick-start.intro ? There is a good documentation there. You shouldn't have used any optimization while you're compiling.

给妤﹃绝世温柔 2024-12-08 13:58:15

如果您想检查自动工具驱动的编译的结果(它实际上在您的构建目录中创建了一个 shell 脚本),您可能想尝试以下操作:

libtool --mode=execute valgrind -v --leak-check=full --show-reachable=yes  ./my_binary

If you want to check the result of an autotools-powered compilation (it really creates a shell script in your build dir), you might want to try this instead:

libtool --mode=execute valgrind -v --leak-check=full --show-reachable=yes  ./my_binary
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文