我在我的程序上运行valgrind,它没有返回内存泄漏。然而,它显示了更多的自由,而不是分配,我真的不确定为什么。
提前感谢
==4234== HEAP SUMMARY:
==4234== in use at exit: 0 bytes in 0 blocks
==4234== total heap usage: 304 allocs, 542 frees, 81,820 bytes allocated
==4234==
==4234== All heap blocks were freed -- no leaks are possible
==4234==
==4234== For counts of detected and suppressed errors, rerun with: -v
==4234== Use --track-origins=yes to see where uninitialised values come from
==4234== ERROR SUMMARY: 3555 errors from 13 contexts (suppressed: 0 from 0)发布于 2020-04-24 22:04:57
您可以使用--trace-malloc=yes选项检查分配了哪些地址。我建议不要在大型应用程序中使用它!
例如,使用这个小应用程序
int main()
{
int* pi = new int;
delete pi;
}我得到了
paulf> ./vg-in-place --trace-malloc=yes ../vg_examples/noleak
==88971== Memcheck, a memory error detector
==88971== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==88971== Using Valgrind-3.16.0.GIT and LibVEX; rerun with -h for copyright info
==88971== Command: ../vg_examples/noleak
==88971==
--88971-- _Znwm(4) = 0x5800040
--88971-- _ZdlPv(0x5800040)
==88971==
==88971== HEAP SUMMARY:
==88971== in use at exit: 0 bytes in 0 blocks
==88971== total heap usage: 1 allocs, 1 frees, 4 bytes allocated
==88971==
==88971== All heap blocks were freed -- no leaks are possible
==88971==
==88971== For lists of detected and suppressed errors, rerun with: -s
==88971== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)几个注意事项
valgrind而不是vg-in-place,除非你自己构建Valgrind。paulf> ./vg-in-place --trace-malloc=yes ../vg_examples/noleak 2>&1 | /usr/bin/c++filt
[snip]
--89034-- operator new(unsigned long)(4) = 0x5800040
--89034-- operator delete(void*)(0x5800040)https://stackoverflow.com/questions/61391066
复制相似问题