This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/53521] [4.5/4.6/4.7/4.8 Regression] Memory leak with zero-sized array constructor
- From: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 31 May 2012 08:19:34 +0000
- Subject: [Bug fortran/53521] [4.5/4.6/4.7/4.8 Regression] Memory leak with zero-sized array constructor
- Auto-submitted: auto-generated
- References: <bug-53521-4@http.gcc.gnu.org/bugzilla/>
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.