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/47637] [OOP] Memory leak involving INTENT(OUT) CLASS argument w/ allocatable components
Date: Tue, 08 Feb 2011 22:51:00 -0000	[thread overview]
Message-ID: <bug-47637-4-cp4p0ZPL0X@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-47637-4@http.gcc.gnu.org/bugzilla/>

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |janus at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #2 from janus at gcc dot gnu.org 2011-02-08 22:38:15 UTC ---
Something like this should fix it:


Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c    (revision 169891)
+++ gcc/fortran/trans-decl.c    (working copy)
@@ -3192,7 +3192,35 @@ init_intent_out_dt (gfc_symbol * proc_sym, gfc_wra
        else if (f->sym->value)
       gfc_init_default_dt (f->sym, &init, true);
       }
+    else if (f->sym && f->sym->attr.intent == INTENT_OUT
+         && f->sym->ts.type == BT_CLASS
+         && !CLASS_DATA (f->sym)->attr.class_pointer
+         && CLASS_DATA (f->sym)->ts.u.derived->attr.alloc_comp)
+      {
+    tree decl = build_fold_indirect_ref_loc (input_location,
+                          f->sym->backend_decl);
+    tmp = CLASS_DATA (f->sym)->backend_decl;
+    tmp = fold_build3_loc (input_location, COMPONENT_REF,
+                TREE_TYPE (tmp), decl,
+                tmp, NULL_TREE);
+    tmp = build_fold_indirect_ref_loc (input_location, tmp);
+    tmp = gfc_deallocate_alloc_comp (CLASS_DATA (f->sym)->ts.u.derived,
+                      tmp,
+                      CLASS_DATA (f->sym)->as ?
+                      CLASS_DATA (f->sym)->as->rank : 0);

+    if (f->sym->attr.optional
+        || f->sym->ns->proc_name->attr.entry_master)
+      {
+        present = gfc_conv_expr_present (f->sym);
+        tmp = build3_loc (input_location, COND_EXPR, TREE_TYPE (tmp),
+                  present, tmp,
+                  build_empty_stmt (input_location));
+      }
+
+    gfc_add_expr_to_block (&init, tmp);
+      }
+
   gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
 }



This gets rid of the memleaks in both comment #0 and comment #1 for me, but is
not regtested yet.


  parent reply	other threads:[~2011-02-08 22:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-07 22:15 [Bug fortran/47637] New: Memory leak involving derived types " townsend at astro dot wisc.edu
2011-02-08 20:16 ` [Bug fortran/47637] [OOP] Memory leak involving INTENT(OUT) CLASS argument " janus at gcc dot gnu.org
2011-02-08 22:51 ` janus at gcc dot gnu.org [this message]
2011-02-09 10:01 ` janus at gcc dot gnu.org
2011-02-09 14:10 ` burnus at gcc dot gnu.org
2011-02-09 16:01 ` janus at gcc dot gnu.org
2011-02-09 16:05 ` janus 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-47637-4-cp4p0ZPL0X@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).