c - Valgrind 结果干净但分配多于释放

标签 c pointers memory-leaks heap-memory valgrind

我从 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/

相关文章:

c - 我的阶乘程序出了什么问题???

c++ - 对 C++ 从函数返回引用的困惑

c - 如何知道 C 中的 char 数组是否有空元素?

指向 char 变量的 C++ char 指针

c++ - 内存/速度问题的一般策略

c - 参数比预期更多的函数调用

C通过分隔符将字符串拆分为token并保存为变量

c - ANSI C 书籍链接列表章节中的错误编译示例

javascript - 当我误用Interval Observable时如何释放内存?

c# - 内存泄漏问题。使用 OpenCVSharp 在 Unity 中进行眼动追踪