C++ Valgrind显示出比allocs更多的自由度

C++ Valgrind显示出比allocs更多的自由度,c++,valgrind,C++,Valgrind,我在我的程序上运行了valgrind,它没有返回内存泄漏。然而,它显示出比allocs更多的自由度,我不知道为什么 提前谢谢 ==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

我在我的程序上运行了valgrind,它没有返回内存泄漏。然而,它显示出比allocs更多的自由度,我不知道为什么

提前谢谢

==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)


您可以使用
--trace malloc=yes
选项检查分配的地址。我建议不要在大型应用程序上使用它

例如,使用这个小应用程序

int main()
{
   int* pi = new int;
   delete pi;
}

我明白了

几张便条

  • 您可能希望运行
    valgrind
    而不是
    vg in-place
    ,除非您自己正在构建valgrind
  • 函数名已损坏。如果要查看未损坏的名称,可以运行

  • 如果您希望我们帮助查找此问题的原因,您需要至少显示一些代码!可能是在计算nullptr值的释放量。@AdrianMole我只是不知道是哪部分代码引起的,valgrind没有向我提供它有问题的那行代码with@1201ProgramAlarm这会导致我的程序在将来出现问题吗?释放空指针是可以的,不会导致任何问题。
    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)
    
    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)