http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56461



--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-26 
15:58:34 UTC ---

Created attachment 29542

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29542

opts* memory leak fixes



Another thing, something that bothered me for a while and clutters valgrind

--leak-check=full dumps all the time is options handling.  Leaks like:

==1284== 222 bytes in 10 blocks are definitely lost in loss record 393 of 479

==1284==    at 0x4A0881C: malloc (vg_replace_malloc.c:270)

==1284==    by 0x111C627: xmalloc (xmalloc.c:147)

==1284==    by 0x10CC7F9: generate_canonical_option(unsigned long, char const*,

int, cl_decoded_option*) (opts-common.c:279)

==1284==    by 0x10CE089: generate_option(unsigned long, char const*, int,

unsigned int, cl_decoded_option*) (opts-common.c:926)

==1284==    by 0x10CDFA4: handle_generated_option(gcc_options*, gcc_options*,

unsigned long, char const*, int, unsigned int, int, unsigned int, cl_

option_handlers const*, diagnostic_context*) (opts-common.c:903)

==1284==    by 0x10C8846: maybe_default_option(gcc_options*, gcc_options*,

default_options const*, int, bool, bool, bool, unsigned int, cl_option_h

andlers const*, unsigned int, diagnostic_context*) (opts.c:388)

==1284==    by 0x10C88D7: maybe_default_options(gcc_options*, gcc_options*,

default_options const*, int, bool, bool, bool, unsigned int, cl_option_

handlers const*, unsigned int, diagnostic_context*) (opts.c:411)

==1284==    by 0x10C8BA6: default_options_optimization(gcc_options*,

gcc_options*, cl_decoded_option*, unsigned int, unsigned int, unsigned int,

cl_option_handlers const*, diagnostic_context*) (opts.c:590)

==1284==    by 0x95DC47: decode_options(gcc_options*, gcc_options*,

cl_decoded_option*, unsigned int, unsigned int, diagnostic_context*)

(opts-global.c:332)

==1284==    by 0xA50AF4: toplev_main(int, char**) (toplev.c:1936)

==1284==    by 0x10C220F: main (main.c:36)



The attached patch (untested) attempts to deal with that by using an obstack

for the option string allocation where we know we don't want to bother with

figuring out how the strings are allocated.  Using obstack should be tiny bit

faster and more importantly, all the allocated strings will be still reachable,

so valgrind won't complain about them.

Reply via email to