Fix memory leak in cp-support.c
authorYao Qi <yao.qi@linaro.org>
Wed, 9 Aug 2017 11:39:16 +0000 (12:39 +0100)
committerYao Qi <yao.qi@linaro.org>
Wed, 9 Aug 2017 11:39:16 +0000 (12:39 +0100)
commite88e8651cf3415ba440ee17eb1b22b7d2e8368be
tree0fc0fa9cc96a6a8588dca8b24ef2180e12e6c142
parentf5a29eb0a6637abcafb1e54d53fae9bcaa6fbbd8
Fix memory leak in cp-support.c

The return value of cp_comp_to_string was never freed, creating a
sizable memory leak detectable with valgrind.

==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M
==21225==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225==    by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225==    by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M
==21225==    by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M
==21225==    by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M
==21225==    by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M
==21225==    by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M
==21225==    by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M
==21225==    by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M
==21225==    by 0x5D6CF6: linespec_parse_basic (linespec.c:1907)

==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M
==21279==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21279==    by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21279==    by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M
==21279==    by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M
==21279==    by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M
==21279==    by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M
==21279==    by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M
==21279==    by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159)

This patch fixes the leak.  It is a regression by 2f408ecb.

gdb:

2017-08-09  Alex Lindsay  <alexlindsay239@gmail.com>
    Yao Qi  <yao.qi@linaro.org>

* cp-support.c (cp_canonicalize_string_full): Use
gdb::unique_xmalloc_ptr<char>.
(cp_canonicalize_string): Likewise.
gdb/ChangeLog
gdb/cp-support.c
This page took 0.032953 seconds and 4 git commands to generate.