我正在测试内存泄漏的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,但这就是我为获得此输出而做的事情)
答案 0 :(得分:0)
可能会出现误报(例如,在共享库初始化程序中,或类似libcrypto.so
的内容泄漏某些分配)。
但是,您应该经常检查 - 很可能您忘记了一些分配。
在您的输出中,我们可以看到:
Command: ./a.out --leak-check=full --track-origins=yes`
这表明你已经用:
调用了valgrindvalgrind ./a.out --leak-check=full --track-origins=yes
你应该使用它:
valgrind --leak-check=full --track-origins=yes ./a.out
如果发现您无法控制的泄漏(或其他诊断),因为它是第三方库的内部信息,您可以制作suppression file