https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65925
Bug ID: 65925 Summary: Memory leak with source allocation nested inside the source of another source allocation 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: --- Valgrind reports a memory leak with the code below for gfortran 6.0.0 (and 4.10 and 5.0.0): $ cat reduced-gforLeak.f90 type IndexSpace end type type,extends(IndexSpace) :: OuterProductSpace end type type base class(IndexSpace),allocatable :: b end type type,extends(base) :: subdata endtype class(base),allocatable :: d allocate(d,source = newData()) contains type(subdata) function newData() allocate(newData%base%b,source = OuterProductSpace()) end function end $ gfortran reduced-gforLeak.f90 $ valgrind ./a.out ==3960== Memcheck, a memory error detector ==3960== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==3960== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==3960== Command: ./a.out ==3960== ==3960== ==3960== HEAP SUMMARY: ==3960== in use at exit: 17 bytes in 3 blocks ==3960== total heap usage: 28 allocs, 25 frees, 12,692 bytes allocated ==3960== ==3960== LEAK SUMMARY: ==3960== definitely lost: 17 bytes in 2 blocks ==3960== indirectly lost: 0 bytes in 1 blocks ==3960== possibly lost: 0 bytes in 0 blocks ==3960== still reachable: 0 bytes in 0 blocks ==3960== suppressed: 0 bytes in 0 blocks ==3960== Rerun with --leak-check=full to see details of leaked memory ==3960== ==3960== For counts of detected and suppressed errors, rerun with: -v ==3960== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) $ gfortran --version GNU Fortran (GCC) 6.0.0 20150422 (experimental)