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; }