public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* move_alloc for types holding allocatable members
@ 2015-10-08 16:18 Alberto Luaces
  2015-10-08 17:57 ` Steve Kargl
  2015-10-08 19:35 ` Anton Shterenlikht
  0 siblings, 2 replies; 6+ messages in thread
From: Alberto Luaces @ 2015-10-08 16:18 UTC (permalink / raw)
  To: fortran

Hello,

I am investigating a memory leak involving "move_alloc" and data types
having allocatable members themselves.

It seems that after a move_alloc call over an array, the allocatable
members of the types that the array is holding are not synchronized, and
thus a leak happens when the array is eventually deallocated.

I have a test case, but had no luck when trying to find similar issues
in the bug tracker.  Is this a known problem (gfortran 5.2.1)?

Thanks,

Alberto

--8<---------------cut here---------------start------------->8---
module alloctest

  type myallocatable
     integer, allocatable:: i(:)
  end type myallocatable

contains
  subroutine f(num, array)
    implicit none
    integer, intent(in) :: num
    integer :: i
    type(myallocatable):: array(:)

    do i = 1, num
       allocate(array(i)%i(5))
    end do

  end subroutine f
end module alloctest

program name
  use alloctest
  implicit none
  type(myallocatable), allocatable:: myarray(:), mytemp(:)

  allocate(myarray(7))
  call f(size(myarray), myarray)

  myarray(3)%i = 6
  print *, myarray(3)%i

  allocate(mytemp(20))
  call move_alloc(mytemp, myarray)

  print *, myarray(3)%i

  deallocate(myarray)
end program name
--8<---------------cut here---------------end--------------->8---

-- 
Alberto

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

end of thread, other threads:[~2015-10-09  8:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-08 16:18 move_alloc for types holding allocatable members Alberto Luaces
2015-10-08 17:57 ` Steve Kargl
2015-10-08 19:06   ` Alberto Luaces
2015-10-08 20:34     ` Steve Kargl
2015-10-09  8:23       ` Alberto Luaces
2015-10-08 19:35 ` Anton Shterenlikht

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).