From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115239 invoked by alias); 22 May 2015 22:57:50 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 115203 invoked by uid 48); 22 May 2015 22:57:46 -0000 From: "pault at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/66079] [6 Regression] memory leak with source allocation in internal subprogram Date: Fri, 22 May 2015 22:57:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 6.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pault at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pault at gcc dot gnu.org X-Bugzilla-Target-Milestone: 6.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-05/txt/msg01965.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66079 --- Comment #5 from Paul Thomas --- Created attachment 35603 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35603&action=edit Nearly OK patch The attached bootstraps and regtests on 6.0.0. The following runs without memory leaks and fixes problems as indicated: type subdata integer, allocatable :: b endtype ! block call newRealVec ! end block contains subroutine newRealVec type(subdata), allocatable :: d, e, f character(:), allocatable :: g, h, i allocate(d,source=subdata(1)) ! memory was lost, now OK allocate(e,source=d) ! OK allocate(f,source=create (99)) ! memory was lost, now OK if (d%b .ne. 1) call abort if (e%b .ne. 1) call abort if (f%b .ne. 99) call abort allocate (g, source = greeting1("good day")) if (g .ne. "good day") call abort allocate (h, source = greeting2("hello")) if (h .ne. "hello") call abort allocate (i, source = greeting3("hiya!")) if (i .ne. "hiya!") call abort end subroutine function create (arg) result(res) integer :: arg type(subdata), allocatable :: res allocate(res, source = subdata(arg)) end function function greeting1 (arg) result(res) ! memory was lost, now OK character(*) :: arg Character(:), allocatable :: res allocate(res, source = arg) end function function greeting2 (arg) result(res) character(5) :: arg Character(:), allocatable :: res allocate(res, source = arg) end function function greeting3 (arg) result(res) character(5) :: arg Character(5), allocatable :: res, res1 allocate(res, source = arg) ! Caused an ICE - now OK allocate(res1, source = arg) ! Caused an ICE - now OK if (res1 .ne. res) call abort end function end Just a small amount of cleaning up to do before submission. Paul