From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2256 invoked by alias); 27 Apr 2014 14:32:23 -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 Received: (qmail 2209 invoked by uid 48); 27 Apr 2014 14:32:18 -0000 From: "burnus at gcc dot 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:32:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 4.5.0 X-Bugzilla-Keywords: patch, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pault at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-04/txt/msg02013.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41936 --- Comment #4 from Tobias Burnus --- (In reply to Dominique d'Humieres from comment #3) > + 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) > + { > + tmp = build_fold_indirect_ref_loc (input_location, se->expr); > + tmp = gfc_deallocate_alloc_comp (expr->ts.u.derived, tmp, expr->rank); Calling gfc_deallocate_alloc_comp for BT_CLASS looks wrong. You have to call the finalization wrapper - to ensure that not only the allocatable components of the declared type but also the ones of the effective/actual type are deallocated. Additionally, that ensure that user's finalizer is called when it exists. (For BT_DERIVED, you may also have to call the finalization wrapper - but only if the type has finalizers.)