http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53389
Bug #: 53389
Summary: memory leak when assigning array function result to
allocatable array, where one of its supplied arguments
is itself an array function result.
Classification: Unclassified
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: [email protected]
ReportedBy: [email protected]
The following test code leaks memory rapidly - reproduced on Ubuntu's gfortran
4.6.3, with gfortran 4.7.1 and with a nightly build of 4.8, trunk revision
187620 - default optimisation flags (none specified). As far as I've narrowed
it down, it seems to occur when an array function result is assigned to an
allocatable array, where one of the arguments supplied to this function is
itself an array function result. In the example below, the outer function and
the function supplied as an argument are the same, and the returned array is an
automatic array, but that does not seems to be necessary to reproduce the
problem.
module foo
implicit none
contains
function filler(array, val)
real, dimension(:), intent(in):: array
real, dimension(size(array)):: filler
real, intent(in):: val
filler=val
end function filler
end module
program test
use foo
implicit none
real, dimension(:), allocatable:: x, y
integer, parameter:: N=1000*1000
integer:: i
allocate( x(N), y(N) )
y=0.0
do i=1, N
print *,i
x=filler(filler(y, real(2*i)), real(i))
y=y+x
end do
end program test