我正在运行代码,我遇到错误
*检测到glibc * /home/build/bin/../bin/OPENSUSE_12.2_X86_64/reader:已损坏 双链表:0x0000000003df6dc0 *
我尝试通过valgrind重新运行它,以了解是否存在任何内存泄漏问题。我把它作为
运行valgrind --leak-check = full -v ./myprog
由于程序没有完成并且停止了valgrind摘要如下:
总堆使用中的> ==5335== Process terminating with default action of signal 2 (SIGINT) > ==5335== at 0x54E4007: kill (in /lib64/libc-2.15.so) > ==5335== by 0x429473: ??? (in /bin/bash) > ==5335== by 0x42A313: wait_for (in /bin/bash) > ==5335== by 0x462BFE: execute_command_internal (in /bin/bash) > ==5335== by 0x463360: execute_command (in /bin/bash) > ==5335== by 0x41B7F0: reader_loop (in /bin/bash) > ==5335== by 0x41B4C9: main (in /bin/bash) > ==5335== > ==5335== HEAP SUMMARY: > ==5335== in use at exit: 37,513 bytes in 1,074 blocks > ==5335== total heap usage: 1,922 allocs, 848 frees, 72,605 bytes allocated > ==5335== > ==5335== Searching for pointers to 1,074 not-freed blocks > ==5335== Checked 220,224 bytes > ==5335== > ==5335== LEAK SUMMARY: > ==5335== definitely lost: 0 bytes in 0 blocks > ==5335== indirectly lost: 0 bytes in 0 blocks > ==5335== possibly lost: 0 bytes in 0 blocks > ==5335== still reachable: 37,513 bytes in 1,074 blocks > ==5335== suppressed: 0 bytes in 0 blocks > ==5335== Reachable blocks (those to which a pointer was found) are not shown. > ==5335== To see them, rerun with: --leak-check=full --show-reachable=yes > ==5335== > ==5335== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) > --5335-- > --5335-- used_suppression: 2 dl-hack3-cond-1 > ==5335== > ==5335== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
:1,922个分配,848个释放,我想知道这里是否有任何问题? 但在错误摘要中没有错误。我想知道我是否应该关注代码或内存泄漏中的任何问题?
答案 0 :(得分:0)
这个摘要基本上意味着你没有先释放相关的已分配内存,也没有丢弃任何指针(将它们设置为NULL
)。当程序退出时,任何已分配的内存(无论是否泄露)都将被释放。但是,你是对的 - 你没有泄漏任何内存,所以如果你的程序运行了很长一段时间,你就不会用完堆空间。
理想情况下,您仍应尝试自行清理 - 查找malloc
次来电,而不进行任何相应的free
来电。