Issue
I'm running valgrind with the command:
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes
--max-stackframe=10485760 --log-file=valgrind_output.txt ./MyPrg
I have built my executable with symbols.
The output includes:
==30169== HEAP SUMMARY:
==30169== in use at exit: 72,704 bytes in 1 blocks
==30169== total heap usage: 688,466 allocs, 688,465 frees, 622,080,633 bytes
allocated
==30169==
==30169== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==30169== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/
vgpreload_memcheck-amd64-linux.so)
==30169== by 0x4EC3EFF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==30169== by 0x40106B9: call_init.part.0 (dl-init.c:72)
==30169== by 0x40107CA: call_init (dl-init.c:30)
==30169== by 0x40107CA: _dl_init (dl-init.c:120)
==30169== by 0x4000C69: ??? (in /lib/x86_64-linux-gnu/ld-2.23.so)
==30169== by 0x5: ???
==30169== by 0xFFF000242: ???
==30169== by 0xFFF000247: ???
==30169== by 0xFFF00024A: ???
==30169== by 0xFFF00024C: ???
==30169== by 0xFFF00024F: ???
==30169== by 0xFFF000252: ???
==30169==
==30169== LEAK SUMMARY:
==30169== definitely lost: 0 bytes in 0 blocks
==30169== indirectly lost: 0 bytes in 0 blocks
==30169== possibly lost: 0 bytes in 0 blocks
==30169== still reachable: 72,704 bytes in 1 blocks
==30169== suppressed: 0 bytes in 0 blocks
How can I get more information to find out what variable(s) pertain to this reachable block?
Update 1
It looks like someone else gets the same output: https://bugs.archlinux.org/task/45051
I am using Linux Mint 18.1.
Update 2
Using gdb I get the output:
[Inferior 1 (process 15499) exited normally]
Solution
The warning points to the allocation in dl-init.c
line 72:
==30169== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30169== by 0x4EC3EFF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
// --- start of your code ---
==30169== by 0x40106B9: call_init.part.0 (dl-init.c:72)
==30169== by 0x40107CA: call_init (dl-init.c:30)
==30169== by 0x40107CA: _dl_init (dl-init.c:120)
I do not think, it is a problem in your code but the dynamic library loader. See this answer, for more details: c++ valgrind shows memory leak in hello world
According to the bug report, it is fixed in gcc 6. When I tested with gcc 7.2.1 and clang 5.0.1, I also do not get the valgrind warning.
Answered By - Philipp Claßen Answer Checked By - Cary Denson (WPSolving Admin)