gpt4 book ai didi

c - 只是一个循环,还有 33 个泄漏

转载 作者:太空狗 更新时间:2023-10-29 14:53:33 25 4
gpt4 key购买 nike

在我的 mac 上看一些奇怪的东西:

$> cat main.c
#include <stdio.h>   
int main(int ac, char **av) {
for (int i = 0; i < ac; i++)
printf("%s\n", av[i]);
return 0;
}
$> gcc main.c -std=c99
$> valgrind ./a.out hello my friends

结果如下:

==725== Memcheck, a memory error detector
==725== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==725== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==725== Command: ./a.out hello my friends
==725==
--725-- ./a.out:
--725-- dSYM directory is missing; consider using --dsymutil=yes
./a.out
hello
my
friends
==725==
==725== HEAP SUMMARY:
==725== in use at exit: 6,146 bytes in 33 blocks
==725== total heap usage: 33 allocs, 0 frees, 6,146 bytes allocated
==725==
==725== LEAK SUMMARY:
==725== definitely lost: 0 bytes in 0 blocks
==725== indirectly lost: 0 bytes in 0 blocks
==725== possibly lost: 0 bytes in 0 blocks
==725== still reachable: 6,146 bytes in 33 blocks
==725== suppressed: 0 bytes in 0 blocks
==725== Rerun with --leak-check=full to see details of leaked memory
==725==
==725== For counts of detected and suppressed errors, rerun with: -v
==725== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1 from 1)

如果有人知道原因,并且可以向我解释这些泄漏是从哪里来的,我将不胜感激!!

祝你有美好的一天:-)

最佳答案

这些不是泄漏。列为 still reachable 的对象应该不会给您带来麻烦。如果您在上面的行中有一个非零值,那么它应该敲响警钟!

列为 still reachable 的那 33 个 block 很可能是标准库在 printf 调用中分配的一些 block 。没什么好担心的。

也考虑看看 this answer类似的问题。

关于c - 只是一个循环,还有 33 个泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8550853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com