Hello!

> cgraph*.c and ipa-*.c use xstrdup on strings when dumping them via
> fprintf, leaking all of the duplicated buffers.
>
> Is/was there a reason for doing this?

Yes, please see [1] and PR 53136 [2]. As said in [1]:

"There is a problem with multiple calls of cgraph_node_name in fprintf
dumps. Please note that C++ uses caching in
cxx_printable_name_internal (aka LANG_HOOKS_DECL_PRINTABLE_NAME), so
when cxx_printable_name_internal is called multiple times from printf
(i.e. fprintf "%s/%i -> %s/%i"), it can happen that the first string
gets evicted by the second call, before fprintf is fully evaluated."

> Taking them out fixes these leaks (seen when dumping is enabled):

But you will get "Invalid read of size X" instead.

The patch at [1] fixed these, but introduced memory leaks, which were
tolerable at the time:

"I think that small memory leak is tolerable here (the changes are
exclusively in the dump code), and follows the same approach as in
java frontend."

It seems that these assumptions are not valid anymore.

[1] https://gcc.gnu.org/ml/gcc-patches/2012-04/msg01904.html
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53136

Uros.

Reply via email to