re PR fortran/79230 ([OOP] Run time error: double free or corruption)
authorAndre Vehreschild <vehre@gcc.gnu.org>
Sun, 5 Feb 2017 12:02:15 +0000 (13:02 +0100)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Sun, 5 Feb 2017 12:02:15 +0000 (13:02 +0100)
gcc/fortran/ChangeLog:

2017-02-05  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/79230
* trans-array.c (structure_alloc_comps): Ignore pointer components when
freeing structures.

gcc/testsuite/ChangeLog:

2017-02-05  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/79230
* gfortran.dg/der_ptr_component_2.f90: New test.

From-SVN: r245191

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/der_ptr_component_2.f90 [new file with mode: 0644]

index ff47dc4d1bad479a38106e46acd11fa4dbd37a13..63af2aeec6b700457e0b62f33f697efb06ab945d 100644 (file)
@@ -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 a3aab8e45286ed61c5b1cffadeabcfeb73f4ddf8..d0dfc264f872fcd20a0c0d9250ea2bb5a7bc08e7 100644 (file)
@@ -8220,9 +8220,17 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl,
 
          /* 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 77aba28d51e4c2fa1a5bfd26c530cdddfe0b8fab..af60081ba0b711c22ed8a4fbe5a153c3066b3769 100644 (file)
@@ -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.
diff --git a/gcc/testsuite/gfortran.dg/der_ptr_component_2.f90 b/gcc/testsuite/gfortran.dg/der_ptr_component_2.f90
new file mode 100644 (file)
index 0000000..4eb0869
--- /dev/null
@@ -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
+
+