[英]valgrind reporting errors and definitely lost when using realloc()
[英]Valgrind reporting memory definitely lost without errors
我正在測試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重新運行,但這是我為獲得此輸出所做的工作)
這是可能的誤報現象(例如,在共享庫的初始化,或之類的東西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
如果您發現由於第三方庫的內部原因而無法控制的泄漏(或其他診斷),則可以制作抑制文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.