public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: "José Rui Faustino de Sousa" <jrfsousa@gmail.com>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: PING: [Patch, fortran v2] PR fortran/92621 Problems with memory handling with allocatable intent(out) arrays with bind(c)
Date: Mon, 14 Jun 2021 15:32:08 +0000	[thread overview]
Message-ID: <538c19f7-3649-39f6-214c-0131bdce1533@gmail.com> (raw)
In-Reply-To: <a256be86-21ae-4b36-228f-19e57b645e91@gmail.com>

*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 <jrfsousa@gmail.com>
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.


      reply	other threads:[~2021-06-14 15:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26 11:21 José Rui Faustino de Sousa
2021-06-14 15:32 ` José Rui Faustino de Sousa [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=538c19f7-3649-39f6-214c-0131bdce1533@gmail.com \
    --to=jrfsousa@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).