[Bug fortran/53521] [4.5/4.6/4.7/4.8 Regression] Memory leak with zero-sized array constructor
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu May 31 08:44:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53521
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-05-31 08:19:34 UTC ---
(In reply to comment #7)
> (In reply to comment #5)
> > That is clearly a bug in the Fortran FE.
> > D.1888 = __builtin_realloc (atmp.0.data, D.1887);
> ...
> > if (D.1887 == 0)
> > D.1888 = 0B;
> > means that D.1888 isn't freed.
>
> Well spotted! I got distracted by the valgrind result of 0 bytes - and by the
> later FREE check, which should be okay.
>
> The problem is in gcc/fortran/trans.c's gfc_call_realloc.
I guess passing MAX (D.1887, 1) as second argument to realloc above and
omitting that if (D.1887 == 0) D.1888 = 0B; stmt would be easiest and hopefully
not much slower (both sequences have one conditional). Because, I believe you
still have free at the end anyway.
More information about the Gcc-bugs
mailing list