public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/106750] Memory leak calling array slice of derived type containing `allocatable` entries Date: Tue, 30 Aug 2022 18:59:00 +0000 [thread overview] Message-ID: <bug-106750-4-wmnLJNtsyd@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-106750-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106750 anlauf at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2022-08-30 Ever confirmed|0 |1 Keywords| |wrong-code Status|UNCONFIRMED |NEW CC| |anlauf at gcc dot gnu.org --- Comment #1 from anlauf at gcc dot gnu.org --- Confirmed. The memory leak comes from not deallocating the temporary when we have a vector index. OTOH using an equivalent array constructor creates the necessary free()'s, as can be seen from the dump. Reduced testcase: program test implicit none type :: t integer, allocatable :: a(:) end type t integer, parameter :: n = 100 type(t), allocatable :: ts(:) integer :: j(n),i allocate(ts(1)) ts(1) = t([1,2,3]) do i=1,n j(i) = do_with_array([ts(1),ts(1)]) ! no leak ! j(i) = do_with_array( ts([1,1]) ) ! MEMORY LEAK end do print *, 'sum=',sum(j) deallocate(ts) contains integer function do_with_array(ts) result(l) type(t), intent(in) :: ts(:) l = 1 end function end program test
next prev parent reply other threads:[~2022-08-30 18:59 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-08-26 9:37 [Bug fortran/106750] New: Memory leak calling section " federico.perini at gmail dot com 2022-08-30 18:59 ` anlauf at gcc dot gnu.org [this message] 2022-08-30 19:05 ` [Bug fortran/106750] Memory leak calling array slice " anlauf at gcc dot gnu.org 2022-08-31 10:46 ` federico.perini at gmail dot com 2022-09-11 20:11 ` mikael 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-106750-4-wmnLJNtsyd@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: linkBe 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).