From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 12CCD385381A; Mon, 14 Jun 2021 15:32:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 12CCD385381A Received: by mail-wr1-x42c.google.com with SMTP id i94so14985732wri.4; Mon, 14 Jun 2021 08:32:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:to:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=lt+jcnYF3cF7mOGDdGAu5M9GLv1dwqEcpoNUPqigtdY=; b=tAusx423uq3Yqy/t0xD/QcSbZXPlXN+xvYBCANL08QZpaYLsf4QqgqRKzpJD8+IUI8 WfHE/ygr6XiH5Ft6wdLy6gs9sATYX5lI2ZIKpd631b9kYJ9rAKu2BkNaqMYZlf2JsDCP XJvm0vQCJDxzvaZOdmw0QZZ5rFbw8XYsH6pIMYLEkM6lVMTXV2z+Njm2QFfytop8UKUX SwU0SQviNhy2RBeBoAUV5EIaSYFqkDUm3UJ2Wzc7PEb8/F/HdF9Auq3pqQVlZbD7khPo T+K9R5BhM7PEeAU/2EC95bdBEGj08Ro/CjsyuRaoaMjijskBNm4aCx9+wWESvhL4APL5 OvFQ== X-Gm-Message-State: AOAM532i1S4PUPVzBFFm2StmHXUIlkN5+LOXt7fW32FVXYMPqdCIfF/E 8s1SnWfUjtukkhrEcf99pJBnzod6SWc= X-Google-Smtp-Source: ABdhPJwuXpMUpgurPijgKQHNRKgqpmUIhO8AFnNfAFGada/eBEsfn0RqgG6bzatgA4WQQl4tCBULVA== X-Received: by 2002:a5d:484b:: with SMTP id n11mr18903187wrs.34.1623684730371; Mon, 14 Jun 2021 08:32:10 -0700 (PDT) Received: from ?IPv6:2001:8a0:7d79:6000:ee57:8710:ea76:b2e1? ([2001:8a0:7d79:6000:ee57:8710:ea76:b2e1]) by smtp.googlemail.com with ESMTPSA id n10sm16840768wre.95.2021.06.14.08.32.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Jun 2021 08:32:10 -0700 (PDT) Subject: PING: [Patch, fortran v2] PR fortran/92621 Problems with memory handling with allocatable intent(out) arrays with bind(c) References: To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org From: =?UTF-8?Q?Jos=c3=a9_Rui_Faustino_de_Sousa?= X-Forwarded-Message-Id: Message-ID: <538c19f7-3649-39f6-214c-0131bdce1533@gmail.com> Date: Mon, 14 Jun 2021 15:32:08 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jun 2021 15:32:14 -0000 *PING* -------- Forwarded Message -------- Subject: [Patch, fortran v2] PR fortran/92621 Problems with memory handling with allocatable intent(out) arrays with bind(c) Date: Mon, 26 Apr 2021 11:21:25 +0000 From: José Rui Faustino de Sousa To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Hi all! Proposed patch to: PR92621 - Problems with memory handling with allocatable intent(out) arrays with bind(c) Patch tested only on x86_64-pc-linux-gnu. The code currently generated tries to deallocate the undefined artificial cfi.n pointer before it is associated with the allocatable array. Since the cfi.n pointer is undefined attempting to free it is really a bad idea and it will frequently segfault. Consequently, since the deallocation is done before the cfi.n pointer is associated with anything, the allocatable array is never freed, like it should, and it will be passed still allocated causing subsequent attempts to allocate it to fail. Version 2 is basically a ping, fixes a typo, replaces an if block with a flag to make reviewing easier and replaces a call to malloc with calloc to make Valgrind happy. Thank you very much. Best regards, José Rui Fortran: Fix segfaults due to freeing undefined pointer [PR92621] gcc/fortran/ChangeLog: PR fortran/92621 * trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): Add code to deallocate allocatable intent(out) dummy array arguments and slightly rearrange code. (gfc_conv_procedure_call): Add a flag to avoid double frees, removes unnecessary checks for bind(c) objects and obsolete comments. libgfortran/ChangeLog: PR fortran/92621 * runtime/ISO_Fortran_binding.c (gfc_desc_to_cfi_desc): replaces a call to malloc with calloc to make Valgrind happy. gcc/testsuite/ChangeLog: PR fortran/92621 * gfortran.dg/bind-c-intent-out.f90: Changes regex to match the changes in code generation. * gfortran.dg/PR92621.f90: Improved new test.