https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94361
Bug ID: 94361 Summary: Memory leak in nested types with final Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: antony at cosmologist dot info Target Milestone: --- The code below leaks memory (mem grows with each loop interation), but does not if the "FINAL" is commented. The issue is also present in trunk (10.0.1 20200218), and may be a reduced test case for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94109 (in which case the problem was introduced around 8.3.1, but I have not tested versions extensively). module debug private Type TypeWithFinal contains FINAL :: finalizer !No leak if this line is commented end type Type Tester real, dimension(:), allocatable :: Dat Type(TypeWithFinal) :: X end Type Type :: TestType2 Type(Tester) :: T end type TestType2 public Leaker contains subroutine Leaker type(TestType2) :: Test allocate(Test%T%Dat(100000000)) end subroutine subroutine finalizer(this) Type(TypeWithFinal) :: this end subroutine finalizer end module program run use debug implicit none integer i do i=1, 10000 call Leaker() call sleep(1) end do end program