C语言 Valgrind报告内存绝对丢失,没有错误

sy5wg1nm  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(72)

我正在测试C代码的内存泄漏,似乎找不到泄漏的来源,因为有0个错误。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)

字符串
代码写在几个文件中,由数百行组成,所以在这里发布可能有点多。有人能解释一下这里的问题吗?或者你需要看到实际的代码才能给予答案吗?我只能找到很少的关于valgrind的文档,我被困在这里了。
(valgrind建议使用--leak-check=full进行填充,但这就是我为获得此输出所做的)

eoigrqb6

eoigrqb61#

可能会出现误报(例如,在共享库初始化器中,或者像libcrypto.so这样的东西,它确实泄漏了一些分配)。
但是,您应该始终检查-很可能您忘记了某些分配。
在您的输出中,我们可以看到:

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

字符串
这表明您已经调用了valgrind:

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


应该使用这个:

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


如果您发现一个泄漏(或其他诊断),由于它是第三方库内部的,您无法控制,您可以创建一个suppression file

相关问题