This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ping [PATCH, Fortran, v1] Fix deallocation of nested derived typed components


On 12/08/2016 05:42 AM, Andre Vehreschild wrote:
Ping!

On Fri, 2 Dec 2016 13:28:40 +0100
Andre Vehreschild <vehre@gmx.de> wrote:

Hi all,

attached patch fixes on ICE, when freeing a scalar allocatable component in a
derived typed coarray.

Furthermore does it fix freeing of nested derived typed allocatable
components. A simple code explains the bug that is solved by the patch:

type inner
  integer, allocatable :: i
end type
type outer
  type(inner), allocatable :: link
end type

type(outer), allocatable :: obj

allocate(obj)
allocate(obj%link)
allocate(obj%link%i)

deallocate(obj%link)
deallocate(obj) ! <- this will generate pseudo-pseudo-code of the kind:

if (obj.link.i != 0)  // But link is already NULL, i.e. a crash occurs.
  free(obj.link.i)

The patch fixes this by moving the code for freeing link.i into the check if
link is allocated, i.e.:

if (obj.link != 0) {
  if (obj.link.i != 0)  {
    free (obj.link.i);
    obj.link.i = 0;
  }
  free (obj.link);
  obj.link = 0;
}

Furthermore does the patch ensure that the handle of an allocatable component
is set to 0.

Bootstraped and regtested ok on x86_64-linux/F23. Ok for trunk?

Regards,
	Andre



I think OK.

Jerry


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]