public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "songtao.thu at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/57957] [F03] Double free with allocatable components
Date: Fri, 25 Oct 2013 20:31:00 -0000	[thread overview]
Message-ID: <bug-57957-4-NI77PLkFMR@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57957-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Tao Song <songtao.thu at gmail dot com> ---
(In reply to janus from comment #2)
> (In reply to Tobias Burnus from comment #1) 
> > For GCC 4.9, one needs to wrap the code in the main program in BLOCK/END
> > BLOCK as otherwise the end-of-scope deallocation does not trigger, which
> > causes the failure.
> 
> Updated test case:
> 
> 
> program main
> 
>   implicit none
> 
>   type :: type1
>     real, allocatable :: anum(:)
>   end type
> 
>   type :: type2
>     type(type1) :: temp
>   end type
> 
> 
>   block
>     type(type1) :: t1
>     type(type2) :: t2
> 
>     t1 = type1([0.,1.])
>     t2 = type2(t1)
>   end block
> end
> 
> 
> 
> Note: The double free goes away when changing the line
> 
> t2 = type2(t1)
> 
> to
> 
> t2%temp = t1
> 
> That means the actual problem is not the auto-dealloc itself (which is done
> properly), but the construction of t2: With the second variant, a deep copy
> is done (allocating a separate chunk of memory for t2%temp), while in the
> first one t2%temp only gets a reference to the memory allocated for t1
> (which is of course wrong). Since both t1 and t2 are auto-deallocated, we
> try to free that memory twice.

Do you mean in fortran the default structure constructor would yield a shadow
copying? Is this in the standard?

Thank you.

Tao Song


  parent reply	other threads:[~2013-10-25 20:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-23  0:56 [Bug fortran/57957] New: Double free or corruption (fasttop) songtao.thu at gmail dot com
2013-07-23  2:14 ` [Bug fortran/57957] " songtao.thu at gmail dot com
2013-07-23  8:04 ` [Bug fortran/57957] Double free with allocatable components burnus at gcc dot gnu.org
2013-08-21 12:14 ` [Bug fortran/57957] [F03] " janus at gcc dot gnu.org
2013-10-25 20:31 ` songtao.thu at gmail dot com [this message]
2015-04-18  9:24 ` mikael at gcc dot gnu.org
2015-04-18  9:50 ` dominiq at lps dot ens.fr
2015-10-21  0:20 ` dominiq at lps dot ens.fr

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-57957-4-NI77PLkFMR@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).