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

            Bug ID: 66082
           Summary: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with
                    derived type array constructor actual argument
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: damian at sourceryinstitute dot org
  Target Milestone: ---

The code below demonstrates a memory leak generated by an automatic array dummy
argument with a corresponding actual argument that is a derived type array
constructor with an allocatable component.  Changing the dummy argument
declaration "foo(n)" to an assumed shape array "foo(:)" eliminates the leak.

Damian

$ cat reduced.f90 
  type foo_t
     real, allocatable :: bigarr
  end type 
  block
    type(foo_t) :: foo 
    allocate(foo%bigarr) 
    call foo_1d(1,[foo]) ! definitely lost
  end block
contains
  subroutine foo_1d(n,foo)
    integer n
    type(foo_t) :: foo(n)
  end subroutine 
end 
$ gfortran reduced.f90 
$ valgrind ./a.out
==7891== Memcheck, a memory error detector
==7891== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. 
==7891== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==7891== Command: ./a.out
==7891== 
==7891== 
==7891== HEAP SUMMARY:
==7891==     in use at exit: 4 bytes in 1 blocks
==7891==   total heap usage: 26 allocs, 25 frees, 12,662 bytes allocated
==7891== 
==7891== LEAK SUMMARY:
==7891==    definitely lost: 4 bytes in 1 blocks
==7891==    indirectly lost: 0 bytes in 0 blocks
==7891==      possibly lost: 0 bytes in 0 blocks
==7891==    still reachable: 0 bytes in 0 blocks
==7891==         suppressed: 0 bytes in 0 blocks
==7891== Rerun with --leak-check=full to see details of leaked memory
==7891== 
==7891== For counts of detected and suppressed errors, rerun with: -v
==7891== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
$ gfortran --version
GNU Fortran (GCC) 6.0.0 20150503 (experimental)

Reply via email to