我从 Valgrind 得到这个结果:
==24810== HEAP SUMMARY:
==24810== in use at exit: 0 bytes in 0 blocks
==24810== total heap usage: 9 allocs, 6 frees, 0 bytes allocated
==24810==
==24810== LEAK SUMMARY:
==24810== definitely lost: 0 bytes in 0 blocks
==24810== indirectly lost: 0 bytes in 0 blocks
==24810== possibly lost: 0 bytes in 0 blocks
==24810== still reachable: 0 bytes in 0 blocks
==24810== suppressed: 0 bytes in 0 blocks
它说没有内存泄漏。在我看来这是一个不错的结果。但是,这些 9 allocs,6 frees 怎么样?看起来我还没有在某处释放一些内存。我检查了代码,有3个全局常量指针。也许它们不被视为错误,但打印为未免费?
我应该担心这个还是应该认为代码没有错误? 谢谢你们。 ....只是试图理解所有 ANSI C 与指针和内存分配的麻烦:)))
格言
最佳答案
在 valgrind 网站上 http://valgrind.org/docs/manual/quick-start.html#quick-start.interpret
"definitely lost": your program is leaking memory -- fix it!
"probably lost": your program is leaking memory, unless you're doing funny things with pointers (such as moving them to point to the middle of a heap block).
所以对于你的情况,你的程序应该是好的。
关于c - Valgrind 结果干净但分配多于释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13773434/