public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vterzi1996 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/114613] New: ALLOCATE with SOURCE forgets to finalize temporary instances
Date: Fri, 05 Apr 2024 20:48:14 +0000	[thread overview]
Message-ID: <bug-114613-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114613

            Bug ID: 114613
           Summary: ALLOCATE with SOURCE forgets to finalize temporary
                    instances
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vterzi1996 at gmail dot com
  Target Milestone: ---

Consider the following minimal example:
```
module lib
    private
    type,public::list
    contains
        final::list_final
    end type
    interface list
        procedure list_new
    end interface
contains
    function list_new()result(this)
        type(list)::this
        print*,'list_new'
    end
    subroutine list_final(this)
        type(list),intent(inout)::this
        print*,'list_final'
    end
end


program prog
    use lib
    type(list),allocatable::obj
    allocate(obj,source=list())  ! obj=list()
end
```

Only `list_new` is printed, since `list_final` is never called to finalize the
temporary `list()` instance after the `allocate` statement, what can lead to a
memory leak. This issue can be fixed by replacing `allocate(obj,source=list())`
with `obj=list()`.

A larger example was already discussed here:
https://stackoverflow.com/questions/78279925/right-way-to-allocate-type-instances-containing-pointers-in-fortran
and one of the experienced Stack Overflow users thinks that it is a bug of
gfortran.

                 reply	other threads:[~2024-04-05 20:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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-114613-4@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).