public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "janus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/48700] memory leak with MOVE_ALLOC
Date: Sun, 15 May 2011 11:35:00 -0000	[thread overview]
Message-ID: <bug-48700-4-AdIV9jNnEz@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-48700-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48700

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[OOP] memory leak with      |memory leak with MOVE_ALLOC
                   |MOVE_ALLOC  of polymorphic  |
                   |variables                   |

--- Comment #2 from janus at gcc dot gnu.org 2011-05-15 11:05:24 UTC ---
(In reply to comment #0)
> ==25909== 176 (96 direct, 80 indirect) bytes in 1 blocks are definitely lost in
> loss record 4 of 4
> ==25909==    at 0x4A05E46: malloc (vg_replace_malloc.c:195)
> ==25909==    by 0x400DCF: MAIN__ (testmv3.f90:30)
> ==25909==    by 0x401729: main (testmv3.f90:22)

This one indeed seems to be a problem with MOVE_ALLOC, but apparently unrelated
to OOP/polymorphism. Reduced test case:


program testmv3
  type bar
    integer, allocatable  :: ia(:), ja(:)
  end type

  type(bar), allocatable :: sm,sm2

  allocate(sm)
  allocate(sm%ia(10),sm%ja(10))

  call move_alloc(sm2,sm)

end program testmv3 


I think the 80 indirectly lost bytes should be the allocatable components
(40+40), while the 96 are probably their array descriptors (48+48).

The MOVE_ALLOC statement is simply translated to:

        sm = sm2;
        sm2 = 0B;

We miss to deallocate "sm", before it gets overridden.

The standard definitely requires this, because
1) it says that the second argument ('TO') of MOVE_ALLOC is INTENT(OUT), cf.
F08:13.7.118,
2) allocatable INTENT(OUT) arguments must be deallocated upon procedure call,
cf. F08:6.7.3.2.


  parent reply	other threads:[~2011-05-15 11:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-20 12:10 [Bug fortran/48700] New: [OOP] memory leak with MOVE_ALLOC of polymorphic variables sfilippone at uniroma2 dot it
2011-05-15 10:45 ` [Bug fortran/48700] " janus at gcc dot gnu.org
2011-05-15 11:35 ` janus at gcc dot gnu.org [this message]
2011-05-15 12:43 ` [Bug fortran/48700] memory leak with MOVE_ALLOC janus at gcc dot gnu.org
2011-05-15 13:44 ` janus at gcc dot gnu.org
2011-05-15 17:56 ` janus at gcc dot gnu.org
2011-05-15 22:32 ` janus at gcc dot gnu.org
2011-05-18 19:12 ` janus at gcc dot gnu.org
2011-05-18 20:13 ` janus at gcc dot gnu.org
2011-11-29 10:02 ` burnus at gcc dot gnu.org
2011-11-29 10:04 ` burnus 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-48700-4-AdIV9jNnEz@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).