move_alloc for types holding allocatable members
Alberto Luaces
aluaces@udc.es
Thu Oct 8 16:18:00 GMT 2015
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
More information about the Fortran
mailing list