From patchwork Sun Apr 2 15:05:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 78256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1785275vqo; Sun, 2 Apr 2023 08:07:22 -0700 (PDT) X-Google-Smtp-Source: AKy350YR3LHc3ZsN0Gyoqs8lX8ojZ35RtGuQsXA5VW6PU75/j37Ko5QuWtJ3A2TUO/HxfCyYOHwf X-Received: by 2002:a17:906:daca:b0:947:f246:b9d8 with SMTP id xi10-20020a170906daca00b00947f246b9d8mr6556289ejb.45.1680448042601; Sun, 02 Apr 2023 08:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680448042; cv=none; d=google.com; s=arc-20160816; b=Vv2fMWv+8m+/v+EkH0WOJwvjWaiTEB0RyknChcSqyNd7PXZQEIcVPeFJEA4j6cmHK3 5Ek72AqkfuDzpw2dakN/tni/ay4O/Ed0CzP+RI2/G9Z68S7mgA9ZoxppTVuXjuj114Bn GOseuGEqxVATpE6jefE6y4VjO4lcCBERsuRoD2hinnndezp264sVW6CVgZSgey0AobBl SzD/rRsxLUppfL40zPoOVZMi7haXUvSaKcr0q5FBUhAAWn+Ds35jtiUpK1EZg0AYZpga upZOWTP3YABeIPlnMzNQKLlHV2CSnhmfPK5RqYrKxqBszzm7pD1uB3ufp+Q0pb9RhCrV f24w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=dUnZb84GUq/oUGD2VePbz9JabCxAwoAfVHWOISUsrnM=; b=GlRYQ/EJsOraajLtUdKCKD8EEFX1yOB3xpv9vcMs9Ivkc9Fit7KkZuOD9azXrA4Rwq Pua6uawc5p4/OHdz7siez5ExRBzLtKToJP7vSHDpQwzQp0ica11ZbI8W3o/Glu/VDkPE ZuMLHmZqEgbJ9X/h86APwiqWp4Cr9DV1NnD3dut3+2cqTsbJaQs6Nz53Qs5pcMhx8hlH /s1q4R+HI7phBt1nK2OxWWKCRTXN6p6ePe+VymLfaf4ZCtqgMdGM5nUQutx3qIsqcBSl yFZRU+HF6LYaoU4rmsayKj/XVnSA7P3kzIXQQu7HYB3FgveYSGIGRgp388rLsvQnX7UR cupA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="UQW/QZtf"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b23-20020a17090636d700b008cd6f50c059si2428329ejc.669.2023.04.02.08.07.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 08:07:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="UQW/QZtf"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1EC63858C36 for ; Sun, 2 Apr 2023 15:06:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1EC63858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680447999; bh=dUnZb84GUq/oUGD2VePbz9JabCxAwoAfVHWOISUsrnM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=UQW/QZtfOded/fPzkyT2idnYxT+YewPk+21cIhOPC5lKONOKDHfZHOB4eIPOgGwkX 9j1V6inXWOIeLhqf3F2Jk5XoorVU1j4EYF/y494Bm9P97FQ7indABfBA/YIc6zUob3 EY4fGZwFu4WsP5SCq/62Hvk0/SlyVOx9lboA3m0k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 626813858C53; Sun, 2 Apr 2023 15:05:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 626813858C53 Received: by mail-ed1-x52b.google.com with SMTP id eg48so107761924edb.13; Sun, 02 Apr 2023 08:05:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680447940; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dUnZb84GUq/oUGD2VePbz9JabCxAwoAfVHWOISUsrnM=; b=DIigW6EAQr5MtrvglT+OpYJQRRowSmGo69H2tc+9lEyaV4d4mlVO6IWqaHZSxdv/Eb utoI+JjhjA6YVpXCJEEsbqhHf6ZzlyBT9OqSZaskYJ5XqbeA7mOrSN2EqZqrtXQJjo/M sWaXeYDnGFK+NnRpZ7J/A4g5Opm8hoOnW2gK+lFu42WyTL+7aMHeZ4V67jYyBhsRlL+K psGXV4rxDNL7/qBem1pbniBsC7afJWCVF78OPBAmg0H6L5I8O5VgzaKyilYfdWtaw4rG w2YOZK53FemNsc+HffOecOa60j3QHF4/2x16DEqHUMI+zuNtzfhRHfyZHaNsGhQfB62k xkbg== X-Gm-Message-State: AAQBX9fbjh4aLNfYuY+ZPtyLz2Tm01zSouZd6XHvnTgAkBIre6TMad2q 7K67Z9+BX80tpkyBOSspR856jL6b5rM= X-Received: by 2002:aa7:d313:0:b0:4f9:e6f1:5c7c with SMTP id p19-20020aa7d313000000b004f9e6f15c7cmr33610491edq.32.1680447940742; Sun, 02 Apr 2023 08:05:40 -0700 (PDT) Received: from nbbrfq ([2001:871:227:1e16:8ec:e883:b72a:18fd]) by smtp.gmail.com with ESMTPSA id m9-20020a50c189000000b004fd2aab4953sm3360051edf.45.2023.04.02.08.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 08:05:38 -0700 (PDT) Received: from b by nbbrfq with local (Exim 4.96) (envelope-from ) id 1pizGz-000Ad0-1Q; Sun, 02 Apr 2023 17:05:37 +0200 To: gcc-patches@gcc.gnu.org Cc: Bernhard Reutner-Fischer , Ian Lance Taylor Subject: [PATCH 1/3] go: Fix memory leak in Integer_expression Date: Sun, 2 Apr 2023 17:05:13 +0200 Message-Id: <20230402150515.40826-2-rep.dot.nop@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762077486708725440?= X-GMAIL-MSGID: =?utf-8?q?1762077486708725440?= From: Bernhard Reutner-Fischer Cc: Ian Lance Taylor gcc/go/ChangeLog: * gofrontend/expressions.cc (Integer_expression::do_import): Fix memory leak. --- gcc/go/gofrontend/expressions.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 4ac55af7433..93f5d5dc52b 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -2728,6 +2728,7 @@ Integer_expression::do_import(Import_expression* imp, Location loc) { go_error_at(imp->location(), "bad number in import data: %qs", real_str.c_str()); + mpfr_clear (real); return Expression::make_error(loc); } } @@ -2743,6 +2744,8 @@ Integer_expression::do_import(Import_expression* imp, Location loc) { go_error_at(imp->location(), "bad number in import data: %qs", imag_str.c_str()); + mpfr_clear (imag); + mpfr_clear (real); return Expression::make_error(loc); } mpc_t cval; @@ -2766,6 +2769,7 @@ Integer_expression::do_import(Import_expression* imp, Location loc) { go_error_at(imp->location(), "bad number in import data: %qs", num.c_str()); + mpz_clear (val); return Expression::make_error(loc); } Expression* ret; @@ -2783,6 +2787,7 @@ Integer_expression::do_import(Import_expression* imp, Location loc) { go_error_at(imp->location(), "bad number in import data: %qs", num.c_str()); + mpfr_clear (val); return Expression::make_error(loc); } Expression* ret = Expression::make_float(&val, NULL, loc); From patchwork Sun Apr 2 15:05:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 78257 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1785900vqo; Sun, 2 Apr 2023 08:08:11 -0700 (PDT) X-Google-Smtp-Source: AKy350Yqrgh+QDqYdRoSjsW25efzVVdbxGtSgST+wjScsx4rvqlFckRjcclNAYwLREtKBRxD05PL X-Received: by 2002:a17:907:a70c:b0:8b1:88aa:46da with SMTP id vw12-20020a170907a70c00b008b188aa46damr35481862ejc.48.1680448091021; Sun, 02 Apr 2023 08:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680448091; cv=none; d=google.com; s=arc-20160816; b=oErR3xC1nUlqgM23fOJr9wPZQB9j3Nkrj8WpVQD/fJtDE9NEG46C4jFMMw9sTiaL63 051ld/t6dzpEU/AR+sor2RuSqEwPWheSqV3NLY4AIBZwcqEqBT4oIXugLQyoYpYjnit1 39tA/WTyXnrPX7N1HhVhtJrIsUEQYJDBq+b0gkJ1fHyB2v5AeHQemXf5tfjmp4Wughm9 9AO79GuMOPID4VX07bLU7RgqVGNNx1G5Lh/ermSU2iwlTS+rNJCYVrvL7h7PeVPHR3Ty uDHSjTVCSNZi3Iy0v6SZTTb26YYuE/r8epDGylLVaQ63GaH2FQhwhgFzXUyBeyksrOb0 sUFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=S5Td04uYYTvHptqbR1rRss3IeqGirYjgywGM8cdKzNk=; b=sjG3MjV4agHBasfTK/iD4hB/lV6uU3FmS+w2YA3pXy2bLpdysD//oqLq+Gm2XpJHPK mns3N/vVN8GerhfOFIiPlRzYFWuuDpVcJYjP9BcSRqcwaPPCrfVcCp5F+ryDtmUJYMVi hBAVgNUh+SNFUBqtWZhYTpyrwQmUcDfI0H94MEyAii5t3zFi6qDisG3BlkyxbHfEyrK2 IzedaJ0q05L7UJ6vRYGN/f+nwZwZB8zH3nKpS5qwb5+iHtZjFlfDqDk53fdLI3ls78dN rTi5zvM1FeZEQdBSKSQbQfiIZHjEx+7o+VDolltsnSEM0DYlrJwfPcKhgUYItbenGgVk zibg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KXRtOCXM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w13-20020a1709062f8d00b009310d4decd9si4098135eji.313.2023.04.02.08.08.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 08:08:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KXRtOCXM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CD013851ABB for ; Sun, 2 Apr 2023 15:07:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CD013851ABB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680448044; bh=S5Td04uYYTvHptqbR1rRss3IeqGirYjgywGM8cdKzNk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=KXRtOCXMHgmvxFinthHuK0ndtu6gdrgZp5dNdbS4b0c9aH92grg66/UPBae755Q8D bAF355bgAcUkO4WkareVeWALpR6Bq/HFnoVgksiRbNGcahpsxjYOBhMczKtbaOjig0 UcI52qOA+kjcrWGd8n32ynydALC6vb2dIGaH+a3I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id F04013858C52; Sun, 2 Apr 2023 15:05:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F04013858C52 Received: by mail-ed1-x533.google.com with SMTP id y4so107931051edo.2; Sun, 02 Apr 2023 08:05:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680447940; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S5Td04uYYTvHptqbR1rRss3IeqGirYjgywGM8cdKzNk=; b=sd5LBQiSaa3P+XrFObrduyVHe7kxirezNtaXrFS3xY7wEtCoouVkYHu5OsLE2eWOAX NQ9ImYJLsvQ/LwAGMk5iyZRxy15WJzsX6OO5QG1uvc2foW0OtVLaIPIOR6QhyZw4WcRc W4F6Ei/f4jkAaQwx1hlDKXcVJCRJjA19CgLmC+M2QSDH879UaBpBnnONL4eZd/gtgTu/ DScc7uBDZGVI8CwJACc+Jdb5gceNokER9qYlEzyYUbBG8TXslNcknuuOqyB2v4TWeC57 Bb+p0tI9zB9LYw9HPSMDS7UC4cZV6IG7dmGQ7H0luAnFQ8vq5XSOkicZ8mLs0ogxOWKm nkDA== X-Gm-Message-State: AAQBX9fnRPtkCeu+wIUn2N2EGOCnOomiqgYEnxRIvxaGcDQjeWsfZ7ol UbSRMWEUNmppiI0wgKsUbmZ+KWqe9v8= X-Received: by 2002:a17:906:1e08:b0:93b:d1ee:5f41 with SMTP id g8-20020a1709061e0800b0093bd1ee5f41mr33805693ejj.31.1680447940308; Sun, 02 Apr 2023 08:05:40 -0700 (PDT) Received: from nbbrfq ([2001:871:227:1e16:8ec:e883:b72a:18fd]) by smtp.gmail.com with ESMTPSA id t28-20020a50ab5c000000b005024faae65esm3366788edc.10.2023.04.02.08.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 08:05:38 -0700 (PDT) Received: from b by nbbrfq with local (Exim 4.96) (envelope-from ) id 1pizGz-000Ad3-1a; Sun, 02 Apr 2023 17:05:37 +0200 To: gcc-patches@gcc.gnu.org Cc: Bernhard Reutner-Fischer , Arthur Cohen , Philip Herron Subject: [PATCH 2/3] rust: Fix memory leak in compile_{integer,float}_literal Date: Sun, 2 Apr 2023 17:05:14 +0200 Message-Id: <20230402150515.40826-3-rep.dot.nop@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762077537495067680?= X-GMAIL-MSGID: =?utf-8?q?1762077537495067680?= From: Bernhard Reutner-Fischer Cc: Arthur Cohen Cc: Philip Herron gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::compile_integer_literal): (CompileExpr::compile_float_literal): Fix memory leak. --- gcc/rust/backend/rust-compile-expr.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 436fc924a13..82078b81953 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -2119,6 +2119,7 @@ CompileExpr::compile_integer_literal (const HIR::LiteralExpr &expr, if (mpz_init_set_str (ival, literal_value.as_string ().c_str (), 10) != 0) { rust_error_at (expr.get_locus (), "bad number in literal"); + mpz_clear (ival); return error_mark_node; } @@ -2133,6 +2134,9 @@ CompileExpr::compile_integer_literal (const HIR::LiteralExpr &expr, rust_error_at (expr.get_locus (), "integer overflows the respective type %<%s%>", tyty->get_name ().c_str ()); + mpz_clear (type_min); + mpz_clear (type_max); + mpz_clear (ival); return error_mark_node; } @@ -2158,6 +2162,7 @@ CompileExpr::compile_float_literal (const HIR::LiteralExpr &expr, != 0) { rust_error_at (expr.get_locus (), "bad number in literal"); + mpfr_clear (fval); return error_mark_node; } @@ -2179,9 +2184,11 @@ CompileExpr::compile_float_literal (const HIR::LiteralExpr &expr, rust_error_at (expr.get_locus (), "decimal overflows the respective type %<%s%>", tyty->get_name ().c_str ()); + mpfr_clear (fval); return error_mark_node; } + mpfr_clear (fval); return real_value; } From patchwork Sun Apr 2 15:05:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 78255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1785013vqo; Sun, 2 Apr 2023 08:06:59 -0700 (PDT) X-Google-Smtp-Source: AKy350b/CDgKK/pzEWYiO1sBJqLV/NKCtA9Itmv3G/sH5qnK8jmrcCUt98hcLeNw8WNcLXcSnB46 X-Received: by 2002:a17:906:16c3:b0:8b1:75a5:4a92 with SMTP id t3-20020a17090616c300b008b175a54a92mr32456631ejd.72.1680448019031; Sun, 02 Apr 2023 08:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680448019; cv=none; d=google.com; s=arc-20160816; b=jV2G/8yaH9BLslCyqzt2adM2x80x9QFdhAwFS7M9wwpNSBJAJwPEfYxDxJW4oMqWd4 9mqzq2AfypXYc0hnD/RxzshJ6YB94r6Nc9swlrcU15n85rUb7/LZ7VSP7WIKkatVR+LS 1exSfoxTRetzk3L3GJ8S7FXwxQ4EarprCLOYd/h5ryEiENKip7wMVy1FMABQ10NvGWE5 zk6ZS1bwVduV4UhFnMoHnYUD9/xC4bojk3y2qj5INVWDq7XCS5EXQx8R+zMFaT8NaPsf D+USaQnrxkZx0oGLxrdSBCohyrYXxSxsR8cmGCHomtPhgoCIA7r8VQObZGcl7X4VhVwo gkIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=4ddGE+cYu1aKp+XvaWm+vBDEUggW6gNWux7egmyAEF8=; b=qWuI5PqkM+VvQKYweFdBjcxdjoiH+nT7UucIA6c8Dg6YBEeWIgHGn0lumpLpHieLq0 seFiC+OWD+wn9Sm9iKQXOU/lbcrGrryVa352GmmWiOCXqQ391B/kYilKxbPQbd+N2KBk CKOvgQhQf+6SzHi8OU4TnF/cstSF38WUM8Df4Losx4GUaS2tNO2PS4Dm9qsFTlwwKOhQ WA06MtNsDL/PFiHpdUni4nhBi1eK6YiR0ksU/6ajRX84B5baQSr3aT7HQeoCYJnxZzHe PNZK6up3SRcdYkmNtNq1gDf7jfbJ1xwJY07LMolxd8U3mqho8CX+6TrkeQv57JJACZhP TyZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=F4x7pQOf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r17-20020a170906551100b0093c96889d25si5837861ejp.407.2023.04.02.08.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 08:06:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=F4x7pQOf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF856384F00E for ; Sun, 2 Apr 2023 15:06:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF856384F00E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680447986; bh=4ddGE+cYu1aKp+XvaWm+vBDEUggW6gNWux7egmyAEF8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=F4x7pQOfDhJ+RdFmSlvof02St/ucMkVRZQaSWnxR2DAIVwvenpTTofSRyx+vQMCU3 pfFBnU5nM9TlOUqBixxf+d1HpuJoNv8vdA624fO0TEQZOt2cNa1pkcyRrd0q0ohQro SSRVtqq2z937CRUzW06wQKnUve3MLKEYN/zP4lNs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 90AA73858C50; Sun, 2 Apr 2023 15:05:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90AA73858C50 Received: by mail-ed1-x531.google.com with SMTP id h8so107880167ede.8; Sun, 02 Apr 2023 08:05:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680447940; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4ddGE+cYu1aKp+XvaWm+vBDEUggW6gNWux7egmyAEF8=; b=ERyKAru0QILGYILn2g/li6oF8dJJTqY2dMxNSUAiOMjokfGQiJg3dzie5kq5sTYkLL Wbk4893cMsdEufs4M8NNuWVuFRWpqHBfk2exin5zY1opZ9MhoajSoUHwx38exljEn440 7klAygdvusI037nYX8aWTDE1kQLEnTkiUbHlO1X7rIzMFFtkuvSsfwpTe9Oc9iS89cc2 0xxi9jvZvNaRW6P1H7Y37TPfDy3ijSa6p3m8HtNQZWLpbP3NPyixnAvpsh+yQl2mCWKo gr80ZP6Ka1V5wnOHMB6oRSBKCPeQwjFwk4/mtom0ZH3/i71D1VsjKa3qNgH70Kj85BhL SmYg== X-Gm-Message-State: AAQBX9drPPfzF4mw6l3yNdUm5iVW/xQhvDsgN7n/QgWG08Pa3vtA3jDU SevPj7TsYfSs2E1n2L+FDHaZY/D567c= X-Received: by 2002:a17:906:9618:b0:884:3174:119d with SMTP id s24-20020a170906961800b008843174119dmr34742793ejx.14.1680447939742; Sun, 02 Apr 2023 08:05:39 -0700 (PDT) Received: from nbbrfq ([2001:871:227:1e16:8ec:e883:b72a:18fd]) by smtp.gmail.com with ESMTPSA id u13-20020a1709063b8d00b0093e261cc8bcsm3326752ejf.58.2023.04.02.08.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 08:05:38 -0700 (PDT) Received: from b by nbbrfq with local (Exim 4.96) (envelope-from ) id 1pizGz-000Ad8-1f; Sun, 02 Apr 2023 17:05:37 +0200 To: gcc-patches@gcc.gnu.org Cc: Bernhard Reutner-Fischer , fortran@gcc.gnu.org Subject: [PATCH 3/3] Fortran: Fix mpz and mpfr memory leaks Date: Sun, 2 Apr 2023 17:05:15 +0200 Message-Id: <20230402150515.40826-4-rep.dot.nop@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762077462213828581?= X-GMAIL-MSGID: =?utf-8?q?1762077462213828581?= From: Bernhard Reutner-Fischer Cc: fortran@gcc.gnu.org gcc/fortran/ChangeLog: * array.cc (gfc_ref_dimen_size): Free mpz memory before ICEing. * expr.cc (find_array_section): Fix mpz memory leak. * simplify.cc (gfc_simplify_reshape): Fix mpz memory leaks in error paths. (gfc_simplify_set_exponent): Fix mpfr memory leak. --- gcc/fortran/array.cc | 3 +++ gcc/fortran/expr.cc | 8 ++++---- gcc/fortran/simplify.cc | 7 ++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index be5eb8b6a0f..8b1e816a859 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -2541,6 +2541,9 @@ gfc_ref_dimen_size (gfc_array_ref *ar, int dimen, mpz_t *result, mpz_t *end) return t; default: + mpz_clear (lower); + mpz_clear (stride); + mpz_clear (upper); gfc_internal_error ("gfc_ref_dimen_size(): Bad dimen_type"); } diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index 7fb33f81788..b4736804eda 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -1539,6 +1539,7 @@ find_array_section (gfc_expr *expr, gfc_ref *ref) mpz_init_set_ui (delta_mpz, one); mpz_init_set_ui (nelts, one); mpz_init (tmp_mpz); + mpz_init (ptr); /* Do the initialization now, so that we can cleanup without keeping track of where we were. */ @@ -1682,7 +1683,6 @@ find_array_section (gfc_expr *expr, gfc_ref *ref) mpz_mul (delta_mpz, delta_mpz, tmp_mpz); } - mpz_init (ptr); cons = gfc_constructor_first (base); /* Now clock through the array reference, calculating the index in @@ -1735,7 +1735,8 @@ find_array_section (gfc_expr *expr, gfc_ref *ref) "at %L requires an increase of the allowed %d " "upper limit. See %<-fmax-array-constructor%> " "option", &expr->where, flag_max_array_constructor); - return false; + t = false; + goto cleanup; } cons = gfc_constructor_lookup (base, limit); @@ -1750,8 +1751,6 @@ find_array_section (gfc_expr *expr, gfc_ref *ref) gfc_copy_expr (cons->expr), NULL); } - mpz_clear (ptr); - cleanup: mpz_clear (delta_mpz); @@ -1765,6 +1764,7 @@ cleanup: mpz_clear (ctr[d]); mpz_clear (stride[d]); } + mpz_clear (ptr); gfc_constructor_free (base); return t; } diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index ecf0e3558df..d1f06335e79 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -6866,6 +6866,7 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, gfc_error ("The SHAPE array for the RESHAPE intrinsic at %L has a " "negative value %d for dimension %d", &shape_exp->where, shape[rank], rank+1); + mpz_clear (index); return &gfc_bad_expr; } @@ -6889,6 +6890,7 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, { gfc_error ("Shapes of ORDER at %L and SHAPE at %L are different", &order_exp->where, &shape_exp->where); + mpz_clear (index); return &gfc_bad_expr; } @@ -6902,6 +6904,7 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, { gfc_error ("Sizes of ORDER at %L and SHAPE at %L are different", &order_exp->where, &shape_exp->where); + mpz_clear (index); return &gfc_bad_expr; } @@ -6918,6 +6921,7 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, "in the range [1, ..., %d] for the RESHAPE intrinsic " "near %L", order[i], &order_exp->where, rank, &shape_exp->where); + mpz_clear (index); return &gfc_bad_expr; } @@ -6926,6 +6930,7 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, { gfc_error ("ORDER at %L is not a permutation of the size of " "SHAPE at %L", &order_exp->where, &shape_exp->where); + mpz_clear (index); return &gfc_bad_expr; } x[order[i]] = 1; @@ -7408,7 +7413,7 @@ gfc_simplify_set_exponent (gfc_expr *x, gfc_expr *i) exp2 = (unsigned long) mpz_get_d (i->value.integer); mpfr_mul_2exp (result->value.real, frac, exp2, GFC_RND_MODE); - mpfr_clears (absv, log2, pow2, frac, NULL); + mpfr_clears (exp, absv, log2, pow2, frac, NULL); return range_check (result, "SET_EXPONENT"); }