public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/114613] New: ALLOCATE with SOURCE forgets to finalize temporary instances
@ 2024-04-05 20:48 vterzi1996 at gmail dot com
  0 siblings, 0 replies; only message in thread
From: vterzi1996 at gmail dot com @ 2024-04-05 20:48 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-05 20:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 20:48 [Bug fortran/114613] New: ALLOCATE with SOURCE forgets to finalize temporary instances vterzi1996 at gmail dot com

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).