c语言 - Valrind 报告"still reachable" empyt 函数



>我正在使用valgrind来检查我的C应用程序的内存使用情况。在第一次测试之后,valgrind报告:

"still reachable: 2,248 bytes in 1 blocks".

我检查了代码,但一眼就找不到问题。所以我开始注释代码的各个部分,试图找到问题所在。

当我的代码中只剩下我时,我感到震惊

int main(void)
{
}; 

并且仍然收到消息,唯一的区别是字节数。

我真的很困惑...

以下是完整的消息:

Running with options : valgrind --leak-check=full --show-reachable=yes
==2557== HEAP SUMMARY:
==2557==     in use at exit: 2,248 bytes in 1 blocks
==2557==   total heap usage: 362 allocs, 361 frees, 14,579 bytes allocated
==2557== 
==2557== 2,248 bytes in 1 blocks are still reachable in loss record 1 of 1
==2557==    at 0x4006171: calloc (vg_replace_malloc.c:593)
==2557==    by 0x4D72250B: monstartup (in /usr/lib/libc-2.15.so)
==2557==    by 0x8048650: __gmon_start__ (in /home/elias/Documents/SL_HTTP/Endosos/bin/Debug/Endosos)
==2557==    by 0x4005421: ??? (in /usr/local/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2557== 
==2557== LEAK SUMMARY:
==2557==    definitely lost: 0 bytes in 0 blocks
==2557==    indirectly lost: 0 bytes in 0 blocks
==2557==      possibly lost: 0 bytes in 0 blocks
==2557==    still reachable: 2,248 bytes in 1 blocks
==2557==         suppressed: 0 bytes in 0 blocks
==2557== 
==2557== For counts of detected and suppressed errors, rerun with: -v
==2557== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Profiling timer expired

我正在使用 Fedrora 4.7.2 中的 gcc 17 进行编译

任何建议将不胜感激。谢谢。

这完全没问题,可以安全地忽略。在本例中,这是似乎已通过分析分配的内存(您可能正在编译启用了分析的代码或链接到某个启用了分析的库)。

您的环境将在调用main之前执行一系列设置操作,这些操作可以分配内存。由于他们知道此内存将一直使用到程序退出,因此他们不会在退出时费心free它,因为这只需要时间而没有任何好处。大部分内存将被 valgrind 报告为"仍然可以访问",并且可以安全地忽略。

谢谢大家。

你是对的。

我正在使用 Code:Blocks 12.11,默认情况下它在编译器设置中启用了 -pg。

相关内容

最新更新