https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66079
Bug ID: 66079 Summary: [6.0 Regression] memory leak with source allocation in internal subprogram 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: --- This leak is superficially similar to Bug 65925, which was reported against GCC 5.0 20150216. The code below, however, exhibits no leak when compiled with the aforementioned version and therefore appears to expose a regression in GCC 6.0 20150503. Also, the code below is much simpler. Unlike the code in 65925, the code below uses no polymorphism, no type extension, no function (only a subroutine with no arguments), only one explicit "allocate", and only one derived type. Also, the procedure that invokes "allocate" is called inside a block construct and no variables are declared in the main program scope. FYI, wrapping the "call newRealVec" in a loop increases the reported leak by 4 bytes for every loop iteration. Damian $ cat source-allocation.f90 type subdata integer, allocatable :: b endtype block call newRealVec end block contains subroutine newRealVec type(subdata), allocatable :: d allocate(d,source=subdata()) ! definitely lost end subroutine end $ gfortran source-allocation.f90 $ valgrind ./a.out ==6209== Memcheck, a memory error detector ==6209== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==6209== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==6209== Command: ./a.out ==6209== ==6209== ==6209== HEAP SUMMARY: ==6209== in use at exit: 4 bytes in 1 blocks ==6209== total heap usage: 27 allocs, 26 frees, 12,718 bytes allocated ==6209== ==6209== LEAK SUMMARY: ==6209== definitely lost: 4 bytes in 1 blocks ==6209== indirectly lost: 0 bytes in 0 blocks ==6209== possibly lost: 0 bytes in 0 blocks ==6209== still reachable: 0 bytes in 0 blocks ==6209== suppressed: 0 bytes in 0 blocks ==6209== Rerun with --leak-check=full to see details of leaked memory ==6209== ==6209== For counts of detected and suppressed errors, rerun with: -v ==6209== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) $ gfortran --version GNU Fortran (GCC) 6.0.0 20150503 (experimental) Copyright (C) 2015 Free Software Foundation, Inc.