public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "janus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/63473] [4.9/5 Regression] Memory leak with ALLOCATABLE, INTENT(OUT) dummy arguments.
Date: Tue, 16 Dec 2014 15:13:00 -0000	[thread overview]
Message-ID: <bug-63473-4-qmy6BeSxal@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-63473-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63473

--- Comment #3 from janus at gcc dot gnu.org ---
Here is a slightly compactified test case:


program testprogram
  implicit none
  type :: mytype_type
    integer, allocatable :: i(:)
  end type
  integer :: n
  type(mytype_type), allocatable :: array(:)

  do n = 1, 2
    print *, allocated(array)
    call allocate_mytype(array)
  end do

contains

  subroutine allocate_mytype(array)
    type(mytype_type), allocatable, intent(out) :: array(:)
    integer :: i
    allocate(array(10))
    do i = 1, 10
      allocate(array(i)%i(5))
      array(i)%i = 0
    end do
  end subroutine

end


With 4.9.1, valgrind shows:


==31043== HEAP SUMMARY:
==31043==     in use at exit: 880 bytes in 21 blocks
==31043==   total heap usage: 43 allocs, 22 frees, 13,201 bytes allocated
==31043== 
==31043== 200 bytes in 10 blocks are definitely lost in loss record 2 of 3
==31043==    at 0x4C2ABA0: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31043==    by 0x400BC6: allocate_mytype.2336 (test.f90:21)
==31043==    by 0x400EF3: MAIN__ (test.f90:11)
==31043==    by 0x400F40: main (test.f90:9)
==31043== 
==31043== 680 (480 direct, 200 indirect) bytes in 1 blocks are definitely lost
in loss record 3 of 3
==31043==    at 0x4C2ABA0: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31043==    by 0x4009A1: allocate_mytype.2336 (test.f90:19)
==31043==    by 0x400EF3: MAIN__ (test.f90:11)
==31043==    by 0x400F40: main (test.f90:9)
==31043== 
==31043== LEAK SUMMARY:
==31043==    definitely lost: 680 bytes in 11 blocks
==31043==    indirectly lost: 200 bytes in 10 blocks
==31043==      possibly lost: 0 bytes in 0 blocks
==31043==    still reachable: 0 bytes in 0 blocks
==31043==         suppressed: 0 bytes in 0 blocks


The first message (200 bytes) occurs with all gfortran versions I tried (and
only in the second loop execution).

The second message (680 bytes) occurs only with 4.9 upwards (and already in the
first loop execution).


  parent reply	other threads:[~2014-12-16 15:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 18:06 [Bug fortran/63473] New: " paul.vandelst at noaa dot gov
2014-12-16 14:50 ` [Bug fortran/63473] [4.9/5 Regression] " janus at gcc dot gnu.org
2014-12-16 15:13 ` janus at gcc dot gnu.org [this message]
2014-12-16 15:26 ` janus at gcc dot gnu.org
2014-12-16 15:34 ` [Bug fortran/63473] " janus at gcc dot gnu.org
2015-08-07 17:26 ` mikael at gcc dot gnu.org

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=bug-63473-4-qmy6BeSxal@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).