From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13302 invoked by alias); 8 Feb 2011 22:38:34 -0000 Received: (qmail 13291 invoked by uid 22791); 8 Feb 2011 22:38:33 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Feb 2011 22:38:28 +0000 From: "janus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/47637] [OOP] Memory leak involving INTENT(OUT) CLASS argument w/ allocatable components X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: janus at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: janus at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Status AssignedTo Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Tue, 08 Feb 2011 22:51:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg01112.txt.bz2 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.