简体   繁体   English

Valgrind 可能会在简单程序中丢失内存

[英]Valgrind possibly lost memory in simple programs

Whatever program I run Valgrind tells me that there are 72 possibly lost bytes in 3 blocks, even with a simple program like:无论我运行什么程序,Valgrind 都会告诉我在 3 个块中有 72 个可能丢失的字节,即使是一个简单的程序,例如:

int main(void)
{
    printf("Hello, World!\n");
    return 0;
}

Do you know if this is a Valgrind bug on Mac OS sierra?您知道这是否是 Mac OS sierra 上的 Valgrind 错误吗?

How could I leak memory with a program like this?我怎么会用这样的程序泄漏内存?

That can very likely happen, if any of the preloaded libraries (eg via LD_PRELOAD ), or any parts of the linked C runtime have memory leaks.如果任何预加载的库(例如通过LD_PRELOAD )或链接的 C 运行时的任何部分存在内存泄漏,这很可能会发生。

There are also a couple of memory allocations performed by the CRT which are never freed on purpose, but typically these are only a one-time thing and only happen once per process. CRT 还执行了一些内存分配,它们永远不会被故意释放,但通常这些只是一次性的事情,并且每个进程只发生一次。

Valgrind can not reliably distinguish between what's part of your application at what isn't. Valgrind 无法可靠地区分您的应用程序的哪些部分不是。 You can only check the stack trace from where the memory was allocated, and decide whether that is your domain or not.您只能从分配内存的位置检查堆栈跟踪,并确定这是否是您的域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM