From patchwork Wed Aug 16 20:16:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 135817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp262286vqi; Wed, 16 Aug 2023 13:18:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrQeaPMPY2j2KApzHDfo5CuKAekJj92zh+WjWBGWawEaiOXOtUaPYpsMBsoQo9YcxXA7PS X-Received: by 2002:aa7:c256:0:b0:523:2811:5531 with SMTP id y22-20020aa7c256000000b0052328115531mr2632894edo.4.1692217080357; Wed, 16 Aug 2023 13:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692217080; cv=none; d=google.com; s=arc-20160816; b=cOyjO3onrDZZSob4SepdahDt1Es8scwwTulwLo6ylr0phlpy4pZEidhZ5qP1j3N92H Bj4mEozyZjS+XX/W8R14T3jGuBqY19YRHI5lLdjOzK/UktyiVYPNgDllkwiWGax1w6cg 6iRctN1C6VLhu7puatx+BDEQOq7rHl4PUIb8KuXIDxXQFOj1AqYFrvnDShoUl4OIbeuk T9ghunxFW1tV2/dY40JDwoI58d/YR2/QtqT8nnNaKcdMVX+PvD/04/I0OcO08uC5/9Iq E74SF8kyW4hfxcCosvVTa72e/NdTC9Y/FvTgo7qwsgtKE0E2Iim8BpQe+yNYQIAP0em4 ZyAg== 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=TXKOpXfcn1MPAD7SXEE9UQKk5+/KKfyUth9YDSiseTI=; fh=QK0YdXSiSCa48e9o4Ff7k6xpBN/ax2bSUZqWzYlsl7Q=; b=sXMXY1NS8t8S29Q4slJuXte9CZCRCANxPY0Nhb49jj2qqVpCC7bPyIeuHp1NhIq4Pg PjbSyu1lBwSQgMOeIj1TZ6qsP5J7/SZ0CdJ9pVfS2nROS1Ex7vXw5kItKEY9+NkBUsoN EhK+4nD/W6O67Z6EsUPR4wiDlWjT+fqg/9l5/QiAFzNE+zvm5Rfz/lhnzlxP+tpeK59U KdFVVC3YuXTHe+CoQ3GdlKYuo1fColQ3afYB5yDxfX+RYxFlPXd/NTr8bAG5X/7nY7+I 1ltXFV+hQqI+y9F6nZEu5SXZGYB/sJ2r/BshZ2x6oRpm/4RbmFNuwRFAIWKxpbQ/X2gJ shvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QyfM2khR; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d3-20020aa7d5c3000000b0052683dac6adsi61628eds.244.2023.08.16.13.18.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 13:18:00 -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=QyfM2khR; 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 4ACE03857351 for ; Wed, 16 Aug 2023 20:17:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4ACE03857351 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692217048; bh=TXKOpXfcn1MPAD7SXEE9UQKk5+/KKfyUth9YDSiseTI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QyfM2khRfAnDtYLBG6Q0xkJ+R7G93m9PoNyVK0G6NDrMsHy3AO846XTc9keFvxFlc Qs3YeI3H1natu5F37mlCtn6OscTEYwEwsRkYDUTc6TiF0AgkUjrES67xrpvYIUBJyS xSUZpJBuH3ZNbsz6jRAc2wGjjLJMhUmy+dOdrmbg= 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 F18213857715; Wed, 16 Aug 2023 20:16:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F18213857715 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.86.80] ([93.207.86.80]) by web-mail.gmx.net (3c-app-gmx-bap14.server.lan [172.19.172.84]) (via HTTP); Wed, 16 Aug 2023 22:16:41 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH,committed] Fortran: fix memleak for character,value dummy of bind(c) procedure [PR110360] Date: Wed, 16 Aug 2023 22:16:41 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:WLs2UXM8mDDbJUsBvn9YVx8NddLB3cx/KCEWe7Fbmpiw6sQ0F1R6qrEVNe2c1eDNE57Lg 6Pw9FU+qoB49cQq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Od 50PMWij6/eP1qGKJ7cnaT7YdmYjF/3Pd9FLSrNFx8yrh0= X-Spam-Status: No, score=-12.6 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_H4, RCVD_IN_MSPIKE_WL, 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: INBOX X-GMAIL-THRID: 1774418217241064429 X-GMAIL-MSGID: 1774418217241064429 Dear all, the attached simple patch fixes a memleak in the frontend when a character literal is passed to a character,value dummy of a bind(c) procedure, by relying on gfc_replace_expr to do the cleanup. (This can be tested e.g. with gfortran.dg/bind_c_usage_13.f03 and running f951 under valgrind). The patch was OK'ed in the PR by Mikael. Pushed as r14-3254-g9ade70bb86c874 after partial regtesting on x86_64-pc-linux-gnu. Thanks, Harald From 9ade70bb86c8744f4416a48bb69cf4705f00905a Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 16 Aug 2023 22:00:49 +0200 Subject: [PATCH] Fortran: fix memleak for character,value dummy of bind(c) procedure [PR110360] Testcase gfortran.dg/bind_c_usage_13.f03 exhibited a memleak in the frontend occuring when passing a character literal to a character,value dummy of a bind(c) procedure, due to a missing cleanup in the conversion of the actual argument expression. Reduced testcase: program p interface subroutine val_c (c) bind(c) use iso_c_binding, only: c_char character(len=1,kind=c_char), value :: c end subroutine val_c end interface call val_c ("A") end gcc/fortran/ChangeLog: PR fortran/110360 * trans-expr.cc (conv_scalar_char_value): Use gfc_replace_expr to avoid leaking replaced gfc_expr. --- gcc/fortran/trans-expr.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 52cd88f5b00..6e9e76cd5c9 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -4044,8 +4044,9 @@ conv_scalar_char_value (gfc_symbol *sym, gfc_se *se, gfc_expr **expr) gfc_typespec ts; gfc_clear_ts (&ts); - *expr = gfc_get_int_expr (gfc_default_character_kind, NULL, - (*expr)->value.character.string[0]); + gfc_expr *tmp = gfc_get_int_expr (gfc_default_character_kind, NULL, + (*expr)->value.character.string[0]); + gfc_replace_expr (*expr, tmp); } else if (se != NULL && (*expr)->expr_type == EXPR_VARIABLE) { -- 2.35.3