use c++ and smart pointers. problem solved.
My advice is DON'T use C++. Avoid it whenever possible.use c++ and smart pointers. problem solved.
Completely agree 6502 . Sorry, eternal noob, most of what you say makes solid sense, but not this timeMy advice is DON'T use C++. Avoid it whenever possible.
only used smart pointers, that might not be too bad. Just don't use all the rest of the C++ gorp.Well, fair enough, fragmentation was probably the wrong word. Let's just say "your heap will slowly grow". I guess we haven't isolated the bug yet though. We don't know for certain where the memory leak is occurring, I was just guessing its a heap leak from the repeated free then malloc shown in the listing. Then again, no-one has answered my question yet, which is why does the hashtable need to use dynamic memory at all? But maybe the leak is happening somewhere else, it's not like we've seen all the code, so who knows.The question is not for embedded software. And memory leaks are not related to fragmentation.
Hello,
Do you have any recommendation?
set history save
add-auto-load-safe-path /usr/local/share/gdb/auto-load/lib/libc++.so.1-gdb.py
set auto-load safe-path /home/paulf/tools/valgrind
valgrind -vgdb-error=0 ./trivialleak
==39967== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==39967== /path/to/gdb ./trivialleak
==39967== and then give GDB the following command
==39967== target remote | /home/paulf/tools/valgrind/libexec/valgrind/../../bin/vgdb --pid=39967
==39967== --pid is optional if only one valgrind process is running
(gdb) target remote | /home/paulf/valgrind/coregrind/vgdb
Remote debugging using | /home/paulf/valgrind/coregrind/vgdb
relaying data between gdb and process 39967
warning: remote target does not support file transfer, attempting to access files from local filesystem.
Reading symbols from /home/paulf/valgrind/memcheck/tests/trivialleak...
Reading symbols from /libexec/ld-elf.so.1...
(No debugging symbols found in /libexec/ld-elf.so.1)
0x0000000004014380 in ?? () from /libexec/ld-elf.so.1
(gdb) b main
Note: breakpoint 1 also set at pc 0x100006e4.
Breakpoint 2 at 0x100006e4: file trivialleak.c, line 12.
(gdb) c
Continuing.
Breakpoint 1, main () at trivialleak.c:12
12 test();
(gdb) mo leak_check full
==41254== All heap blocks were freed -- no leaks are possible
==41254==
(gdb) n
13 return 0;
(gdb) mo leak_check full
==41254== 999 (+999) bytes in 999 (+999) blocks are definitely lost in new loss record 2 of 2
==41254== at 0x4088A60: malloc (vg_replace_malloc.c:451)
==41254== by 0x1000067B: test (trivialleak.c:8)
==41254== by 0x100006E7: main (trivialleak.c:12)
==41254==
==41254== LEAK SUMMARY:
==41254== definitely lost: 999 (+999) bytes in 999 (+999) blocks
==41254== indirectly lost: 0 (+0) bytes in 0 (+0) blocks
==41254== possibly lost: 0 (+0) bytes in 0 (+0) blocks
==41254== still reachable: 1 (+1) bytes in 1 (+1) blocks
==41254== suppressed: 0 (+0) bytes in 0 (+0) blocks
==41254== Reachable blocks (those to which a pointer was found) are not shown.
==41254== To see them, add 'reachable any' args to leak_check
==41254==
(gdb) mo leak_check full reachable any
==41254== 1 bytes in 1 blocks are still reachable in loss record 1 of 2
==41254== at 0x4088A60: malloc (vg_replace_malloc.c:451)
==41254== by 0x1000067B: test (trivialleak.c:8)
==41254== by 0x100006E7: main (trivialleak.c:12)
==41254==
==41254== 999 bytes in 999 blocks are definitely lost in loss record 2 of 2
==41254== at 0x4088A60: malloc (vg_replace_malloc.c:451)
==41254== by 0x1000067B: test (trivialleak.c:8)
==41254== by 0x100006E7: main (trivialleak.c:12)
==41254==
==41254== LEAK SUMMARY:
==41254== definitely lost: 999 bytes in 999 blocks
==41254== indirectly lost: 0 bytes in 0 blocks
==41254== possibly lost: 0 bytes in 0 blocks
==41254== still reachable: 1 bytes in 1 blocks
==41254== suppressed: 0 bytes in 0 blocks