From patchwork Tue Jan 10 21:56:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 41672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2986654wrt; Tue, 10 Jan 2023 13:57:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXtnyukT6zmJrl50aG7MBZJHrE6YtGK+lM7PVIHbDCzDd7mP4xgS5x4vhYoVxLIu+F7uRpT7 X-Received: by 2002:a05:6402:793:b0:493:597e:218b with SMTP id d19-20020a056402079300b00493597e218bmr15051195edy.39.1673387833713; Tue, 10 Jan 2023 13:57:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673387833; cv=none; d=google.com; s=arc-20160816; b=AJuKeVIbN3MgU3wqXCUkCinF5j9vqfRaqe7tUS+Y8zVuCdRyHTsYp6rg1Jg/ScTadD rVcv6kPSrHhoNNS3VszHEo29uu4dsJx6btBsTw1185HSAPIAoZmZXRopB0tCsz4J3cNz wvfzzkbLLYDdF6n9Gw+3Czy13ITZQcsMqJpU91lNLSI2P9K0APN4ObxYP6ECmoJHN5vT 1mYCOPPg+eRC2oDZseYRiJj+N5GGVrqf4rbrq/ZEvLs4Nd/6jQO/lDCWy/sQiWygH7dv v+ev4V9OiNpPdU4/g206wvmZSgv7HNLgVw13INnvuiWKhoYD1H8CmIl+JCc1vXLCWORB Wagw== 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:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oSi+D/jS4dxIbzeYhjVR6kjYHCcjuPnV8LH9trRGL/4=; b=t2yw1/R80sl/EzlYH2SUlaetpO+DqXAt/rCFr1We+3Hz3pU5BZO0IusaYcjab0OVJ5 09/OFKNFdZNMWqMhrNArunAf8CvNym15QZT1I8Y8yhXH2gtZmak/3s5XvmifXrzSj4dI Y0dIr8rVdQPy/qg6sbwA8KNU4pVRDUaBUJYcf13fhpVDGsc5A26KaIZNHGuGXvHckaqu heeWd5tNUYt+qvBkYOoNGEcG8Tlczo0MGtXqOUfj5NDDp7BmejQZshvB2n3lajt5ORgy TizIx9XTLcle5IKuCFrGCDhL+2d7FZiBXfB8k/MSgmVGtSnReen3XRnqnpbWqAL7B0qk Cfcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=genc5YZk; 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 xg11-20020a170907320b00b007bc93454b3fsi12287977ejb.953.2023.01.10.13.57.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 13:57:13 -0800 (PST) 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=genc5YZk; 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 C0E76385800C for ; Tue, 10 Jan 2023 21:57:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0E76385800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673387832; bh=oSi+D/jS4dxIbzeYhjVR6kjYHCcjuPnV8LH9trRGL/4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=genc5YZkZJobdv/2qPEjjLN80G0b4t1fPPM0PPJvsI6wfw72S+UTN2xpWiH3cd3BC Zlzu872ed1yCiRc/1jZcDUdq01LmqndrnthxOg6S7qwhvnMpCbWOCVJ7EdO7666Soq nA0uuTV9lFjuQAjjjX+QUvV1bBiHc/Nrdg0NtvzU= 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.21]) by sourceware.org (Postfix) with ESMTPS id 304403858D33; Tue, 10 Jan 2023 21:56:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 304403858D33 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.83.237] ([93.207.83.237]) by web-mail.gmx.net (3c-app-gmx-bap64.server.lan [172.19.172.134]) (via HTTP); Tue, 10 Jan 2023 22:56:27 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: frontend passes do_subscript leaks gmp memory [PR97345] Date: Tue, 10 Jan 2023 22:56:27 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:WZsajenJ5mubqArJ+Ayk3+pEeA2wrWsWJ2HkXMtEqHjqiDhEnyKxjS7gnCxCTPlcLdrsp 3urvLBHuYCf4rzW+d14NfVNXf88BWM4BF4NcbC72FIVnnlw3NuiVHHpo+uHSBuRCESnNX6T8ufnz SY9i17/ktlPTy+hVXW2dmHiil3jWtaq4kbb1A5YXSspT9BtoF516WD30+lbiJ38svG236zyRiWGM 9/YaDjDZDUwRp7/l9daQaTuIQVOwZpCF/juN3ni4iTjCqKPzKJ/QMrqagPtf/vlqEGXSW5Dcwt0M PM= UI-OutboundReport: notjunk:1;M01:P0:uLq7iXDBCLk=;LkqKZqEnlb3+pG+ZHtlpt7fqr2k cJfxGmhV/xoGTY+UwvnNI/jm2aIJwSqpJATFcQfh5EHhgEgpWrZHfUurcUsrpC9gN0CNhxg5O eDMLexGZclC099nseJkJQjm0z1nSYFR7b3WuHN/rujSSKAqXrxc114WaYGRtEdNFJtJxyPmQi 23xgjbqRBxktNZMSe+xR8UbQIEak+tOKObkiG/8Gdnq2YNr1rqKVkzNqN/muc4+6Iyndp7VFC ZxZRizNAnAfEm/r1bzIv779AeqfSyJjV6543RU9voPvu103DvUS5VZCKhgDP1gBa1w7Lu9KAF fKxB27K2g3C78sfPwZzX9T+g9huId6787gr8hgFpSLx5QeUhC5/TWhl4dOX+2AaSkXsq7BOo2 E7cd7v4WLCw9146yGpem6SxdUVfcZFlebRmxdyw2jL5KLWHdzMFDpkWhAtsXmTknzWvLfXF6g BVp7nidvBwxrcAlc1DeHJdyiWnKzV6WDl0a4trOo6BbmSEBDbNx9RrjfKN6aBRsobINHGb9xa BY3YQ/vcy5ewfqzL2X8tMW/xq5ySxgS1EPTncqH/MFy4kTz5Rn3G7oEftQJmW81XWupmYq5Vz NjhI8xgU3bmI7VJpgfE0vctgQFU5AU/tsOpz34kHcNnfbAcNBFqJOEgtjpVUbL+y2i5+mUShj YKPSVD8tACbzfwbKZ0z3F3wGe1EuCsn0/QSTxs19mGMyeupkR+B80wrw3SWwO4W48EBodSwqj nespTZJzvg1Rp+ZfQMpDydLZMi3GxrZk3pWRltAV58nLCal3FeBbHyaoZnILmj67PhAkDPzzF ivH3eE3wu5bZT7Efz0H78MjjbfPIxawZn0sKyIR4Qu6XQ= X-Spam-Status: No, score=-13.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_LOW, RCVD_IN_MSPIKE_H2, 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: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf 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?1754674321182268286?= X-GMAIL-MSGID: =?utf-8?q?1754674321182268286?= Dear all, the attached obvious patch fixes a memory leak with gmp variables that are set but apparently (=valgrind) never cleared. No new testcase as the current testsuite gives enough coverage (confirmed by trying a faulty version...) and as per discussion with Steve (see PR). Committed after regtesting on x86_64-pc-linux-gnu as: r13-5095-gfec9fc1a17ec44461cee841513f1b6b8ad680fe4 Thanks, Harald From fec9fc1a17ec44461cee841513f1b6b8ad680fe4 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 10 Jan 2023 22:41:17 +0100 Subject: [PATCH] Fortran: frontend passes do_subscript leaks gmp memory [PR97345] gcc/fortran/ChangeLog: PR fortran/97345 * frontend-passes.cc (do_subscript): Clear used gmp variables. --- gcc/fortran/frontend-passes.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc index 612c12d233d..db2b98290d6 100644 --- a/gcc/fortran/frontend-passes.cc +++ b/gcc/fortran/frontend-passes.cc @@ -2892,7 +2892,12 @@ do_subscript (gfc_expr **e) cmp = mpz_cmp (do_end, do_start); if ((sgn > 0 && cmp < 0) || (sgn < 0 && cmp > 0)) - break; + { + mpz_clear (do_start); + mpz_clear (do_end); + mpz_clear (do_step); + break; + } } /* May have to correct the end value if the step does not equal @@ -2965,6 +2970,12 @@ do_subscript (gfc_expr **e) mpz_clear (val); } } + + if (have_do_start) + mpz_clear (do_start); + if (have_do_end) + mpz_clear (do_end); + mpz_clear (do_step); } } } -- 2.35.3