[Bug fortran/49241] New: memory leak with lhs realloc of zero-sized array

xarthisius.kk at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue May 31 11:19:00 GMT 2011


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

           Summary: memory leak with lhs realloc of zero-sized array
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: xarthisius.kk@gmail.com


Following code causes severe memory leak with gfortran 4.6.0 (also with trunk
revision 174463)

program ala
   implicit none

   type :: array_of_foo
      real, dimension(:), allocatable :: p
   end type array_of_foo

   type(array_of_foo), dimension(:), allocatable :: tab

   integer, parameter :: lb = 0
   integer, parameter :: ub = 2
   integer, parameter :: nmax = 10
   integer :: i
   real    :: ran

   do while(.true.)
      allocate(tab(lb:ub))

      allocate(tab(lb)%p(0))
      do i = lb+1, ub
         allocate(tab(i)%p(nmax))
         tab(i)%p(:) = [(i,i=1,nmax)]
      enddo

      tab(lb)%p = [tab(lb)%p, tab(ub)%p]  !!! mem leak if first array has size
0
      ! tab(lb)%p = [tab(ub)%p, tab(lb)%p]    !!! no mem leak

      ! clean up
      do i = lb, ub
         deallocate(tab(i)%p)
      enddo
      deallocate(tab)
   enddo
end program ala

lhs realloc of size(0) = [size(0), size(n)] leaks, whereas size(0) = [size(n),
size(0)] works fine.
Following code does not exhibit this behaviour with Intel compiler (11.1.072)



More information about the Gcc-bugs mailing list