From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 823DA3858D34; Fri, 5 Apr 2024 20:48:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 823DA3858D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712350094; bh=lNfZy3QqRV0kdexeQf2+Kq1FeGeNjMzcz4tmBgvgm70=; h=From:To:Subject:Date:From; b=wWoTsS+RCBsZ9TNHu8Pw2MKl32JRu7JVZKfVU3BJQX1t8r5idhmf/dQXJURZ0LOCj vreo9IIZ8Anx+U0c7G/d21xzSaawd+y8B1/w30ykEsATH9C89BGRPvQUZheLS4kAn8 1iOMPAl2zR88MK25pj9/X+zMZktbQ1ekG6JWq93c= From: "vterzi1996 at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vterzi1996 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114613 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=3Dlist()) ! obj=3Dlist() 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 t= o a memory leak. This issue can be fixed by replacing `allocate(obj,source=3Dli= st())` with `obj=3Dlist()`. A larger example was already discussed here: https://stackoverflow.com/questions/78279925/right-way-to-allocate-type-ins= tances-containing-pointers-in-fortran and one of the experienced Stack Overflow users thinks that it is a bug of gfortran.=