Allocatable components in gfortran
FX Coudert
fxcoudert@gmail.com
Sat Oct 21 19:18:00 GMT 2006
Hi Matthew,
For the short story, please jump to the last paragaph of this mail.
For the even shorter story: not a mingw-specific bug and already
fixed by Paul & Erik.
I've trimmed down your testcase to:
-------------------------------
implicit none
type mumble
integer, allocatable :: arr(:)
end type mumble
type(mumble) :: m
integer :: i
do i = 1, 100000
m = make_mumble()
deallocate(m%arr)
enddo
print *, i
contains
function make_mumble() result(M)
type(mumble) :: M
allocate(M%arr(100000))
end function make_mumble
end
-------------------------------
I diff-ed the code generated on i386-mingw32 (GCC mainline
2006-10-11) and i686-linux (2006-10-21), and the content of the do-
loop is translated into:
i686-linux:
> {
> int4 D.921;
> void * * D.920;
>
> D.920 = &m.arr.data;
> _gfortran_deallocate (D.920, &D.921);
> }
> m = make_mumble ();
> {
> void * * D.922;
>
> D.922 = &m.arr.data;
> _gfortran_deallocate (D.922, 0B);
> }
i386-mingw32:
> {
> int4 D.910;
> void * * D.909;
>
> D.909 = &m.arr.data;
> _gfortran_deallocate (D.909, &D.910);
> }
> m = make_mumble ();
> make_mumble ().arr.data = 0B;
> {
> void * * D.911;
>
> D.911 = &m.arr.data;
> _gfortran_deallocate (D.911, 0B);
> }
So, the de-allocation of m%arr is indeed performed correctly, for
some reason the code generated on i386-mingw is trying to nullify the
return array, but does that by calling the make_mumble function once
again, which is of course where the memory leak occurs.
Now, this appears to not be a mingw-specific problem, as a 2006-10-11
i686-linux compiler (luckily, I had one handy) does emit the same
wrong code. Thus, your problem will be fixed when I upload the next
gfortran binaries, which is (if all goes well) in 4 to 10 hours from
now.
Regards,
FX
More information about the Fortran
mailing list