From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2CEB73858400; Sun, 11 Sep 2022 20:11:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CEB73858400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662927100; bh=Ao7csXmm015ahXB+hmnizSOQPQRZVcqiZLKDQZaMWvs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gs4M5IUBhVGIOJQ/uOGOeC0e/68FTpKTsVPrgBccLUBowoZT+iByU2fURkJqUI8Xm MUhTAVVPgW+1/EJO6XrF39ty0Yx9FvHo805FoD/P5LLlgrS6Esyfj7HG3jFhtsmWo5 OKcYeEzVaGBsz6H0sd7q/ZyW3D7MZkJlWBtkVK98= From: "mikael at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/106750] Memory leak calling array slice of derived type containing `allocatable` entries Date: Sun, 11 Sep 2022 20:11:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 9.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: mikael at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc Message-ID: In-Reply-To: References: 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=3D106750 Mikael Morin changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mikael at gcc dot gnu.org --- Comment #4 from Mikael Morin --- Regarding the other "leak" from the original test: (In reply to federico from comment #0) >=20 > program test (...) > type(t), allocatable :: ts(:) (...) > ! [leak #2] happens if ts is not deallocated. Shouldn't a program work > like a > ! subroutine, and deallocate everything that's going out of scope? > deallocate(ts) >=20 > end program test >=20 Not automatically deallocating is the correct behavior here, I think: > A variable, (...) declared in the scoping unit of a main program, module,= or > submodule implicitly has the SAVE attribute =3D> TS has the save attribute. > The SAVE attribute specifies that a local variable of a program unit or=20 > subprogram retains its association status, allocation status, definition= =20 > status, and value after execution of a RETURN or END statement (...). =3D> TS is not deallocated at the end of the program > When the execution of a procedure is terminated by execution of a RETURN = or=20 > END statement, an unsaved allocatable local variable of the procedure ret= ains > its allocation and definition status if it is a function result or a > subobject thereof; otherwise, if it is allocated it will be deallocated. =3D> this doesn=E2=80=99t apply as TS has the save attribute.=