From patchwork Tue Oct 29 21:00:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 99792 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3B673858C66 for ; Tue, 29 Oct 2024 21:01:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by sourceware.org (Postfix) with ESMTPS id 71F9E3858C98; Tue, 29 Oct 2024 21:00:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71F9E3858C98 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 71F9E3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730235617; cv=none; b=BsACeAmjmzZCqe10Jsuh535sjLdrwvDkWC4wJfaBgpFz9RL8uPPIgwV5xOFLsLuQGzHyEVxFELAWPKt47MtEz8g93vuhobNQbkiqYLFDJjtSv1M7olmP0s7uOtTqTPOfEFQ5EZ+Pha3zBbwpUq6fFKyBeZXlWlilkbb9g2e7sh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730235617; c=relaxed/simple; bh=G0DsVAGVQJNxD+qN8tL+5KBfADXNQOldBHjULFaQ2hI=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=ZuVmB2xw2U7LaHjuTPJ3wvZTaW30dfbAJqu30Rvckaumola3pVJh4FFwwNZjCre7sxAkUhyo4z2ZpULaaJXWKsR6N4Vj1GCxfmdwMeJFs29U+wczSWeeTlxfKdoRPDMplDULd/x9ARBLOSafvi3zHz4mj2GYJkTVbjPS2CRTAAs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1730235611; x=1730840411; i=anlauf@gmx.de; bh=JQIfs0vaKfQMRQaNdel7AAZ8RS/xkkHXSWOss087MkM=; h=X-UI-Sender-Class:MIME-Version:Message-ID:From:To:Subject: Content-Type:Date:cc:content-transfer-encoding:content-type:date: from:message-id:mime-version:reply-to:subject:to; b=CbFcKMfczk77Hyv8wRjhZTgo3KxYjuh2hNvma3+tFMwC2NutozVnHzY1JmN4vu/j ZC1LkQ3s7ZhLa6Oilohl1q+rIctfaeU0shYN0CHiDoZ+m+QgtRF9pUuUKp1DycXbY z4Z78TTYJC5b4WNbUJ5Zof84iMzpXqc/C2E6oV4MBdv/5wUYS2NwAI0x/mjmvKMyj sr37vmrQNJnlDJKWO4Ca09HsCUHMUvWOjVAD+8+LWDdsDqYS3R07p83ReD7GwVI6s hHIdKnIMazIThbWt57yXUngza60PLL9JWjpsE58JmdpJ8fJ/Igg40uK3gyWkG2EN4 9KDS66qirEahtf2SKw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.88.156] ([93.207.88.156]) by trinity-msg-rest-gmx-gmx-live-67cd9ff8f8-s4qbg (via HTTP); Tue, 29 Oct 2024 21:00:11 +0000 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Fortran: fix several front-end memleaks Date: Tue, 29 Oct 2024 21:00:11 +0000 X-UI-CLIENT-META-MAIL-DROP: W10= X-Provags-ID: V03:K1:4e8WXjPiiux+cODoPA0hpXv69bpDqWmJvct2xI+RrJxdoXLOPERHNxdoXjapofFfCi+G8 GHCwQuwyu+mpWHBfb+Zl0LjTfvuSkRXMzBVp1eNXLdfymS86nBVOFXafAj36PE2diG+9/xTQXQEi 02mbpT9YaZd99F8jPl7hln7XrCdiZJTiLuwthODoLwBGJdsrnP9avIPne1AQEgu6iROhrRGA3qd6 ucUsnxNKRIZJtjugooq158MvwxRvVIPgRy89NELZxbbXKJHYdqYjPZPus6bC8eFmISJcXN0BoKH5 5buv+0l3VoBrQN0d7Xn0cAR3xJa55hZGH9hCLyxwMpYgyRKUq4iMt8H9m0ehawO7ZA7L+LLjq+gl 4zgDJntm2Nw UI-OutboundReport: notjunk:1;M01:P0:+ZWoKKG/olM=;pZHkb8OOv9T+ToOznReuJuXqCvR ZfU9rzDPmLDJ88c717wXMmmCaZqC7zi45wIxE5fxgyYufXPGBct8ijcBNPokjrYDHpDPdfyFz IzoR2VwDO0TdpV17xRsXthLLgWnBw8NEam3a4oJt2ecpuAOiTIoyJMlOk2oyIZLx8M+KTe2gj Cy/mFkuzpkaE6rK71oqOu6JINTBXmrGrFtRvAig8hPpHmGcJi7QiFFV8zKAhlFv7UmpugHUxD IURN/GBVz4Ud2sv4qLzt7u0sV0aeFQWcyVgW6Wh0rVj/TXQalbOwpkCqi/oAkcSwp4SuqXawT UsbJi5mld4P250BE66Mj/PfpdcoFDTK8w/BtcNiD1BWGTO5kZhKNgNO+wmqQi00VrDb+9Mbu4 XLXtAsk+xt6n+1obtxHROPU/FaAR5K46yIIOd9kANh075fYiB5V12QB+mLyiNPr2tm43TDDtG 4s9JTnrQoNQN9p1umm6JKhQ/Z1Qt+hLy7fFANbThaSxZumMe27B4JmSJ0pD3Owl1k0b1CO9zZ 4KKhzVDxb4jjQY4IGoDwRUfGgnbzJpm3mNdDq2WNgc/hydttk0sIo331/7BsXoSOBk8kU9OYv FttO8y7dfvNg4esE61pLQAokCuY+hcWxpbKk9aqdAGvFkoUDPyy+jypx285b4Q6Oe55QKf1bu JV9RmcQ5Etx9DxppTfmk3W5MGJqpJDU+iwuKTnuc2w== X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Dear all, while looking at the recent testcase gfortran.dg/pr115070.f90 with f951 running under valgrind, I noticed minor front-end memleaks of gfc_expr's that are probably fallout from a code refactoring, which are fixed by the attached. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 87aaaf3b8614730d0f7ccfe29ee36f4921cf48d2 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 29 Oct 2024 21:52:27 +0100 Subject: [PATCH] Fortran: fix several front-end memleaks gcc/fortran/ChangeLog: * trans-expr.cc (gfc_trans_class_init_assign): Free intermediate gfc_expr's. * trans.cc (get_final_proc_ref): Likewise. (get_elem_size): Likewise. (gfc_add_finalizer_call): Likewise. --- gcc/fortran/trans-expr.cc | 2 ++ gcc/fortran/trans.cc | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index ff8cde93ef4..ddbb5ecf068 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -1890,6 +1890,8 @@ gfc_trans_class_init_assign (gfc_code *code) } gfc_add_expr_to_block (&block, tmp); + gfc_free_expr (lhs); + gfc_free_expr (rhs); return gfc_finish_block (&block); } diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc index 58b93e233a1..1a0ba637058 100644 --- a/gcc/fortran/trans.cc +++ b/gcc/fortran/trans.cc @@ -1128,6 +1128,9 @@ get_final_proc_ref (gfc_se *se, gfc_expr *expr, tree class_container) if (POINTER_TYPE_P (TREE_TYPE (se->expr))) se->expr = build_fold_indirect_ref_loc (input_location, se->expr); + + if (expr->ts.type != BT_DERIVED && !using_class_container) + gfc_free_expr (final_wrapper); } @@ -1155,6 +1158,7 @@ get_elem_size (gfc_se *se, gfc_expr *expr, tree class_container) gfc_conv_expr (se, class_size); gcc_assert (se->post.head == NULL_TREE); + gfc_free_expr (class_size); } } @@ -1467,6 +1471,7 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2, gfc_add_expr_to_block (block, tmp); gfc_add_block_to_block (block, &final_se.post); + gfc_free_expr (expr); return true; } -- 2.35.3