Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Valgrind堆摘要理解_C++_Valgrind_Heap Memory - Fatal编程技术网

C++ Valgrind堆摘要理解

C++ Valgrind堆摘要理解,c++,valgrind,heap-memory,C++,Valgrind,Heap Memory,我正在运行一个代码,遇到如下错误: *glibc检测到*/home/build/bin/./bin/OPENSUSE\u 12.2\u X86\u 64/reader:已损坏 双链接列表:0x0000000003df6dc0* 我试图通过valgrind重新运行它,以了解是否存在内存泄漏问题。我把它当作 valgrind—泄漏检查=满-v./myprog 由于程序未完成并停止,valgrind总结如下: 在堆的总使用量中:1922个allocs,848个frees,我想知道这里是否有问题? 但在

我正在运行一个代码,遇到如下错误:

*glibc检测到*/home/build/bin/./bin/OPENSUSE\u 12.2\u X86\u 64/reader:已损坏 双链接列表:0x0000000003df6dc0*

我试图通过valgrind重新运行它,以了解是否存在内存泄漏问题。我把它当作

valgrind—泄漏检查=满-v./myprog

由于程序未完成并停止,valgrind总结如下:

在堆的总使用量中:1922个allocs,848个frees,我想知道这里是否有问题?
但在错误总结中没有错误。我想知道我是否应该关心代码或内存泄漏中的任何问题?

此摘要基本上意味着您没有先释放相关的已分配内存,就不会丢弃任何指针(将它们设置为
NULL
)。当程序退出时,任何分配的内存(无论是否泄漏)都将被释放。但是,您是正确的-您没有泄漏任何内存,因此如果您的程序运行较长时间,您不会耗尽堆空间


理想的情况是,你仍然应该尝试自己清理干净——寻找
malloc
调用,而不需要任何相应的
free
调用

如果您使用的是数组,它们可以表示为已分配的内存(数组变量实际上只是一个指针)。很难分析当您使用信号终止程序时,程序是否正确地释放了内存,请尝试自然结束它(通过达到main的返回)。
>     ==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)