简体   繁体   English

Valgrind报告内存肯定丢失而没有错误

[英]Valgrind reporting memory definitely lost without errors

I am testing C code for memory leaks and can't seem to find the source of the leaks because there are 0 errors. 我正在测试C代码中的内存泄漏,由于有0个错误,因此似乎找不到泄漏的来源。 Valgrind reports that there is a (quite significant) memory leak: Valgrind报告存在(相当大的)内存泄漏:

==30492== Memcheck, a memory error detector
==30492== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==30492== Using Valgrind-3.14.0.GIT and LibVEX; rerun with -h for copyright 
info
==30492== Command: ./a.out --leak-check=full --track-origins=yes
==30492== 
(This is where the input and output cases are displayed, which are a lot)
==30492== 
==30492== HEAP SUMMARY:
==30492==     in use at exit: 39,155 bytes in 167 blocks
==30492==   total heap usage: 380 allocs, 213 frees, 53,426 bytes allocated
==30492== 
==30492== LEAK SUMMARY:
==30492==    definitely lost: 20,480 bytes in 2 blocks
==30492==    indirectly lost: 2,064 bytes in 1 blocks
==30492==      possibly lost: 0 bytes in 0 blocks
==30492==    still reachable: 348 bytes in 9 blocks
==30492==         suppressed: 16,263 bytes in 155 blocks
==30492== Rerun with --leak-check=full to see details of leaked memory
==30492== 
==30492== For counts of detected and suppressed errors, rerun with: -v
==30492== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

The code is written in a few files and consists of hundreds of lines, so posting it here would probably be a bit much. 该代码写在几个文件中,由数百行组成,因此将其发布在这里可能会有点多。 Could anyone explain what could be the problem here? 谁能解释这可能是什么问题? Or would you need to see the actual code to give an answer? 还是需要查看实际代码来给出答案? I can find only little documentation on valgrind and am quite stuck here. 我只能在valgrind上找到很少的文档,并且非常卡在这里。

(valgrind suggests to rerun with --leak-check=full, but that is what I did to get this output) (valgrind建议使用--leak-check = full重新运行,但这是我为获得此输出所做的工作)

It is possible to get false positives (eg in shared library initializers, or things like libcrypto.so which does leak some allocation). 可能的误报现象(例如,在共享库的初始化,或之类的东西libcrypto.so这不泄露一些分配)。

However, you should always check - most likely you're forgetting some allocation. 但是,您应该始终检查-最有可能忘记一些分配。

In your output, we can see: 在您的输出中,我们可以看到:

  Command: ./a.out --leak-check=full --track-origins=yes` 

This indicates you've invoked valgrind with: 这表明您已使用以下命令调用了valgrind:

valgrind ./a.out --leak-check=full --track-origins=yes

You should use this: 应该使用此:

valgrind --leak-check=full --track-origins=yes ./a.out

If you find a leak (or other diagnostic) that you cannot control because it's internal to a third-party library, you can make a suppression file 如果您发现由于第三方库的内部原因而无法控制的泄漏(或其他诊断),则可以制作抑制文件

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

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