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

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-31 
12:30:53 UTC ---
(In reply to comment #2)
> Following Tobias' suggestion on IRC, the patch
> @@ -2890,6 +2890,7 @@ gfc_undo_symbols (void)
> +          p->common_block->refs--;
> fixes the PR on powerpc-apple-darwin9 without regression.

But it re-introduces the memory leak. The reason that it works is in
gfc_free_symbol:

  if (sym->common_block && sym->common_block->name[0] != '\0')
    {
      sym->common_block->refs--;
      if (sym->common_block->refs == 0)
        free (sym->common_block);

If "refs" is 1, doing twice "refs--" makes the latter -1, preventing the
deletion.


The proper fix is to avoid accessing common_root...->n.common after a common
block has been removed via undo_symbols. And the best way to do so is to delete
the common-block symtree in common_root - which is what the patch in comment 1
does.

Reply via email to