public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alberto Luaces <aluaces@udc.es>
To: fortran@gcc.gnu.org
Subject: move_alloc for types holding allocatable members
Date: Thu, 08 Oct 2015 16:18:00 -0000	[thread overview]
Message-ID: <87y4fdibas.fsf@eps142.cdf.udc.es> (raw)

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

             reply	other threads:[~2015-10-08 16:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-08 16:18 Alberto Luaces [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y4fdibas.fsf@eps142.cdf.udc.es \
    --to=aluaces@udc.es \
    --cc=fortran@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).