我从 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 个分配,6 个释放呢?看起来我还没有在某处释放一些内存。我检查了代码,有 3 个全局 const 指针。也许它们不被视为错误,而是被打印为未释放?
我应该担心这个还是应该认为代码没有错误?谢谢你们。....只是试图理解指针和内存分配的所有 ANSI C 麻烦:)))
格言