0

valgrind prints the following diagnostic from an empty program:

$cat main.cpp
int main(){}
$g++ -std=c++1z -o main main.cpp                         
$valgrind --leak-check=full --show-leak-kinds=all ./main
==26823== Memcheck, a memory error detector
==26823== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==26823== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==26823== Command: ./main
==26823== 
==26823== 
==26823== HEAP SUMMARY:
==26823==     in use at exit: 72,704 bytes in 1 blocks
==26823==   total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated
==26823== 
==26823== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==26823==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26823==    by 0x4E9D62F: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22)
==26823==    by 0x4010109: call_init.part.0 (dl-init.c:78)
==26823==    by 0x40101F2: call_init (dl-init.c:36)
==26823==    by 0x40101F2: _dl_init (dl-init.c:126)
==26823==    by 0x4001309: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)
==26823== 
==26823== LEAK SUMMARY:
==26823==    definitely lost: 0 bytes in 0 blocks
==26823==    indirectly lost: 0 bytes in 0 blocks
==26823==      possibly lost: 0 bytes in 0 blocks
==26823==    still reachable: 72,704 bytes in 1 blocks
==26823==         suppressed: 0 bytes in 0 blocks
==26823== 
==26823== For counts of detected and suppressed errors, rerun with: -v
==26823== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Notice how it states:
"total heap usage: 1 allocs, 0 frees".

It is consistently off by 1 for programs where I also allocate and manage memory properly. This seems to be an issue with the lib standard itself? How can I fix this? I can't seem to find a compiler flag to prevent this.

I have the same issue using the clang++ frontend.

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271

0 Answers0