https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89890
Andrew Wood <andrew at fluidgravity dot co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED Resolution|DUPLICATE |--- --- Comment #3 from Andrew Wood <andrew at fluidgravity dot co.uk> --- Do you mind if I re-open this? I've tried building gcc/gfortran from commit 27c9936ed27 of the git repository (git://gcc.gnu.org/git/gcc.git). The memory leak in the test case I submitted appears to be fixed, but it returns if I make some minor modifications to code.f90: > gfortran --version GNU Fortran (GCC) 9.0.1 20190331 (experimental) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > gfortran -g -O0 -std=f2008 code.f90 > valgrind --tool=memcheck --leak-check=yes --show-leak-kinds=definite ./a.out ==15359== Memcheck, a memory error detector ==15359== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==15359== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==15359== Command: ./a.out ==15359== ==15359== ==15359== HEAP SUMMARY: ==15359== in use at exit: 92 bytes in 2 blocks ==15359== total heap usage: 35 allocs, 33 frees, 13,999 bytes allocated ==15359== ==15359== 92 (88 direct, 4 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2 ==15359== at 0x4C2E01F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==15359== by 0x40145C: __m_MOD_new (arrays.F90:19) ==15359== by 0x4016B0: MAIN__ (arrays.F90:35) ==15359== by 0x401939: main (arrays.F90:28) ==15359== ==15359== LEAK SUMMARY: ==15359== definitely lost: 88 bytes in 1 blocks ==15359== indirectly lost: 4 bytes in 1 blocks ==15359== possibly lost: 0 bytes in 0 blocks ==15359== still reachable: 0 bytes in 0 blocks ==15359== suppressed: 0 bytes in 0 blocks ==15359== ==15359== For counts of detected and suppressed errors, rerun with: -v ==15359== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) code.f90: MODULE m IMPLICIT NONE TYPE, ABSTRACT, PUBLIC :: base INTEGER, ALLOCATABLE :: i(:) END TYPE TYPE, EXTENDS(base), PUBLIC :: subtype CLASS(*), ALLOCATABLE :: x CONTAINS PROCEDURE :: new FINAL :: subtype_final END TYPE CONTAINS FUNCTION new(this) CLASS(subtype) :: this CLASS(base), ALLOCATABLE :: new ALLOCATE(subtype::new) SELECT TYPE ( new ) CLASS IS ( subtype ) ALLOCATE(new%x, SOURCE=this) END SELECT END FUNCTION SUBROUTINE subtype_final(this) TYPE(subtype) :: this IF ( ALLOCATED(this%x) ) DEALLOCATE(this%x) IF ( ALLOCATED(this%i) ) DEALLOCATE(this%i) END SUBROUTINE END MODULE USE m IMPLICIT NONE CLASS(subtype), ALLOCATABLE :: z CLASS(base), ALLOCATABLE :: w ALLOCATE(z) ALLOCATE(z%x, SOURCE=0) ALLOCATE(w, SOURCE=z%new()) DEALLOCATE(w) DEALLOCATE(z) END PROGRAM