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

            Bug ID: 91668
           Summary: Failure to deallocate ALLOCATABLE component of a type
                    in a POINTER array of types on deallocation of POINTER
                    array
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: c.s.brady at warwick dot ac.uk
  Target Milestone: ---

A POINTER array of derived types having allocatable subcomponents does not
deallocate the subcomponents when the POINTER array is deallocated. If the
array of derived types is ALLOCATABLE rather than POINTER the deallocation of
the subcomponents occurs as expected. I believe that this behaviour is not
correct within the F2003 or newer standards. Testing the below code with
valgrind shows 4000 bytes definitely lost.

PROGRAM alloc_test

  TYPE :: subtype
    INTEGER, DIMENSION(:), ALLOCATABLE :: alloc
  END TYPE subtype

  !Switching POINTER to ALLOCATABLE prevents the loss of memory
  TYPE(subtype), POINTER, DIMENSION(:) :: test

  ALLOCATE(test(10))
  DO i = 1, 10
    ALLOCATE(test(i)%alloc(100))
  END DO

  DEALLOCATE(test)

END PROGRAM alloc_test

Reply via email to