public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/49241] New: memory leak with lhs realloc of zero-sized array
@ 2011-05-31 11:19 xarthisius.kk at gmail dot com
  2011-05-31 12:47 ` [Bug fortran/49241] " burnus at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: xarthisius.kk at gmail dot com @ 2011-05-31 11:19 UTC (permalink / raw)
  To: gcc-bugs

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)


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-02-27 12:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-31 11:19 [Bug fortran/49241] New: memory leak with lhs realloc of zero-sized array xarthisius.kk at gmail dot com
2011-05-31 12:47 ` [Bug fortran/49241] " burnus at gcc dot gnu.org
2011-05-31 15:34 ` xarthisius.kk at gmail dot com
2012-02-22 13:43 ` xiaoyuanbo at yeah dot net
2012-12-22 16:30 ` Joost.VandeVondele at mat dot ethz.ch
2013-02-27 12:45 ` dominiq at lps dot ens.fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).