This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/66079] [6 Regression] memory leak with source allocation in internal subprogram
- From: "pault at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 22 May 2015 22:57:46 +0000
- Subject: [Bug fortran/66079] [6 Regression] memory leak with source allocation in internal subprogram
- Auto-submitted: auto-generated
- References: <bug-66079-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66079
--- Comment #5 from Paul Thomas <pault at gcc dot gnu.org> ---
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