public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dominiq at lps dot ens.fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/41936] Memory leakage with allocatables and user-defined operators
Date: Sun, 27 Apr 2014 14:05:00 -0000 [thread overview]
Message-ID: <bug-41936-4-sb0Iri0TLp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-41936-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41936
--- Comment #3 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> Fixed if one adds the code below (copied from gfc_conv_array_parameter).
> I'm afraid this could change a memory leak into a double free (see PR 40850).
> Also, not quite right (even if the middle-end optimizers are likely to fix it)
> because it adds cleanup code to both foo and bar.
With the patch in comment 2, the tests gfortran.dg/alloc_comp_basics_1.f90 and
gfortran.dg/alloc_comp_constructor_1.f90 fail because there are 21 occurrences
of "builtin_free". This is fixed by the following updated patch (against
r209838)
--- ../_clean/gcc/fortran/trans-expr.c 2014-04-25 14:30:23.000000000 +0200
+++ gcc/fortran/trans-expr.c 2014-04-27 16:03:28.000000000 +0200
@@ -6474,6 +6474,19 @@ gfc_conv_expr_reference (gfc_se * se, gf
/* Take the address of that value. */
se->expr = gfc_build_addr_expr (NULL_TREE, var);
+ if ((expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS)
+ && expr->ts.u.derived->attr.alloc_comp && expr->rank
+ && expr->expr_type != EXPR_VARIABLE)
+ {
+ tree tmp;
+
+ tmp = build_fold_indirect_ref_loc (input_location, se->expr);
+ tmp = gfc_deallocate_alloc_comp (expr->ts.u.derived, tmp, expr->rank);
+
+ /* The components shall be deallocated before
+ their containing entity. */
+ gfc_prepend_expr_to_block (&se->post, tmp);
+ }
}
next prev parent reply other threads:[~2014-04-27 14:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-41936-4@http.gcc.gnu.org/bugzilla/>
2011-02-28 21:59 ` mikael at gcc dot gnu.org
2014-04-27 14:05 ` dominiq at lps dot ens.fr [this message]
2014-04-27 14:32 ` burnus at gcc dot gnu.org
2014-04-27 14:47 ` dominiq at lps dot ens.fr
2014-05-04 10:06 ` dominiq at lps dot ens.fr
2014-06-10 11:43 ` dominiq at gcc dot gnu.org
2014-07-07 12:33 ` dominiq at gcc dot gnu.org
2014-07-07 14:00 ` dominiq at lps dot ens.fr
2014-07-07 14:00 ` dominiq at lps dot ens.fr
2009-11-04 9:01 [Bug fortran/41936] New: " burnus at gcc dot gnu dot org
2009-11-12 13:51 ` [Bug fortran/41936] " pault at gcc dot gnu dot 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-41936-4-sb0Iri0TLp@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).