[RFAv2] Fix leak in linespec parser.

Philippe Waroquiers philippe.waroquiers@skynet.be
Tue Nov 27 22:52:00 GMT 2018


On Sun, 2018-11-25 at 20:42 -0500, Simon Marchi wrote:
> Hi Philippe,
> 
> This looks good, but I think we could simplify that a bit by returning
> std::vector objects directly, not dealing with new/delete.  We would move
> returned data in the existing vector.  Would the patch below work?  I think
> everything is set up correctly move-semantic-wise so that there would be no
> copy of vector data.

Hello Simon,

I tested the patch, which effectively solves the leak.
For what concerns the move-semantic-wise: I cannot really comment on that,
as my c++ knowledge is very limited (only working with c++ on GDB at home,
never really learned it).
But valgrind does not show any increase in total nr of blocks allocated:
We see in the below that the unpatched GDB has 7 blocks leaked, and does
the same total nr of block allocations than the patched GDB, so that looks all ok.

The patched GDB allocates in total 2206 bytes more, probably irrelevant
difference caused by environment/file name differences/hash table differing/...

So, FWIW, the patch looks good to me ...

Thanks

Philippe


Unpatched GDB:
==23215== xtree memory report: /bd/home/philippe/gdb/git/build_binutils-gdb/xtmemory.kcg.23215
==23215== HEAP SUMMARY:
==23215==     in use at exit: 35,368,211 bytes in 5,199 blocks
==23215==   total heap usage: 1,187,659 allocs, 1,182,460 frees, 168,153,794 bytes allocated
==23215== 
==23215== LEAK SUMMARY:
==23215==    definitely lost: 144 bytes in 6 blocks
==23215==    indirectly lost: 8 bytes in 1 blocks
==23215==      possibly lost: 61,952 bytes in 144 blocks
==23215==    still reachable: 35,306,011 bytes in 5,043 blocks
==23215==         suppressed: 96 bytes in 5 blocks

Patched GDB:
==23211== xtree memory report: /bd/home/philippe/gdb/git/build_smallthing/xtmemory.kcg.23211
==23211== HEAP SUMMARY:
==23211==     in use at exit: 35,368,053 bytes in 5,193 blocks
==23211==   total heap usage: 1,187,659 allocs, 1,182,466 frees, 168,156,000 bytes allocated
==23211== 
==23211== LEAK SUMMARY:
==23211==    definitely lost: 0 bytes in 0 blocks
==23211==    indirectly lost: 0 bytes in 0 blocks
==23211==      possibly lost: 61,952 bytes in 144 blocks
==23211==    still reachable: 35,306,005 bytes in 5,044 blocks
==23211==         suppressed: 96 bytes in 5 blocks




More information about the Gdb-patches mailing list