public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pault at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-66079-4-RYVR6ENKkm@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-66079-4@http.gcc.gnu.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


  parent reply	other threads:[~2015-05-22 22:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-66079-4@http.gcc.gnu.org/bugzilla/>
2015-05-11 10:51 ` rguenth at gcc dot gnu.org
2015-05-16  8:24 ` pault at gcc dot gnu.org
2015-05-16 15:32 ` pault at gcc dot gnu.org
2015-05-18  1:36 ` damian at sourceryinstitute dot org
2015-05-21  4:25 ` pault at gcc dot gnu.org
2015-05-22 22:57 ` pault at gcc dot gnu.org [this message]
2015-06-11 15:50 ` pault at gcc dot gnu.org
2015-06-13  0:21 ` damian at sourceryinstitute dot org
2015-08-04  9:27 ` mikael at gcc dot gnu.org
2015-08-04  9:32 ` paul.richard.thomas at gmail dot com
2015-10-16  8:34 ` [Bug fortran/66079] [5 " rguenth at gcc dot gnu.org
2015-10-16  8:34 ` rguenth at gcc dot gnu.org
2015-10-18 18:37 ` pault at gcc dot gnu.org
2015-10-18 19:43 ` pault at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-66079-4-RYVR6ENKkm@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).