diff mbox

[Fortran,pr79230,v1,7,Regression,OOP] Run time error: double free or corruption

Message ID 20170205130311.5cf188a7@vepi2
State New
Headers show

Commit Message

Andre Vehreschild Feb. 5, 2017, 12:03 p.m. UTC
Hi Paul,

thanks for the review. Committed as r245191.

Regards,
	Andre

On Sat, 4 Feb 2017 17:03:25 +0000
Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:

> Hi Andre,
> 
> This looks fine to me - OK for trunk.
> 
> Thanks
> 
> Paul
> 
> On 4 February 2017 at 11:59, Andre Vehreschild <vehre@gmx.de> wrote:
> > Hi all,
> >
> > attached patch fixes a regression when a polymorphic pointer component was
> > present. The results was a double free. The attached patch fixes this, by
> > not caring about freeing pointer components as part of gfortran's memory
> > management, i.e., the programmer has to take care about
> > freeing/disassociating the pointer using a finalizer, as is IMO the
> > intention of the Fortran standard.
> >
> > Bootstrapped and regtested ok on x86_64-linux/f25. Ok for trunk (current or
> > next, haven't monitored whether commits are still allowed)?
> >
> > Regards,
> >         Andre
> > --
> > Andre Vehreschild * Email: vehre ad gmx dot de  
> 
> 
>
diff mbox

Patch

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 245190)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@ 
+2017-02-05  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/79230
+	* trans-array.c (structure_alloc_comps): Ignore pointer components when
+	freeing structures.
+
 2017-01-25  Maxim Ostapenko  <m.ostapenko@samsung.com>
 
 	PR lto/79061
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(Revision 245190)
+++ gcc/fortran/trans-array.c	(Arbeitskopie)
@@ -8220,9 +8220,17 @@ 
 
 	  /* Shortcut to get the attributes of the component.  */
 	  if (c->ts.type == BT_CLASS)
-	    attr = &CLASS_DATA (c)->attr;
+	    {
+	      attr = &CLASS_DATA (c)->attr;
+	      if (attr->class_pointer)
+		continue;
+	    }
 	  else
-	    attr = &c->attr;
+	    {
+	      attr = &c->attr;
+	      if (attr->pointer)
+		continue;
+	    }
 
 	  if ((c->ts.type == BT_DERIVED && !c->attr.pointer)
 	     || (c->ts.type == BT_CLASS && !CLASS_DATA (c)->attr.class_pointer))
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 245190)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@ 
+2017-02-05  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/79230
+	* gfortran.dg/der_ptr_component_2.f90: New test.
+
 2017-02-05  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* gcc.target/sparc/20170205-1.c: New test.
Index: gcc/testsuite/gfortran.dg/der_ptr_component_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/der_ptr_component_2.f90	(nicht existent)
+++ gcc/testsuite/gfortran.dg/der_ptr_component_2.f90	(Arbeitskopie)
@@ -0,0 +1,30 @@ 
+! { dg-do run }
+!
+! Freeing the width_data lead to double free. This testcase tests that
+! pr79230 is fixed now.
+
+program main_ut
+  implicit none
+
+  type :: data_t
+     character, allocatable :: c1
+  end type
+
+  type :: t1_t
+     character, allocatable :: c2
+     class(data_t), pointer :: width_data
+  end type
+
+  call evaluator
+
+contains
+
+  subroutine evaluator
+    type(data_t), target :: par_real
+    type(t1_t) :: field
+    field%width_data => par_real
+  end subroutine
+
+end
+
+