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]

[Patch, Fortran] PR45183 Fix charlen freeing (alias: [4.6 Regression] FAIL: gfortran.dg/derived_constructor_char_1.f90)


Fix oversight in the commit of PR 44857: The charlen was not properly freed, leading to double freeing and thus to ICEs. Additionally, the newly added charlen was probably not freed. (Actually, I was not even aware that gfortran has a ns->cl_list...)

Thanks to HJ for reporting the problem.

Build and regtested on x86-64-linux.
Committed as obvious as Rev. 162871.

Tobias

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 162870)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,10 @@
+2010-08-04  Tobias Burnus  <burnus@net-b.de>
+
+	PR fortran/45183
+	PR fortran/44857
+	* resolve.c (resolve_structure_cons): Fix
+	freeing of charlen.
+
 2010-08-04  Mikael Morin  <mikael@gcc.gnu.org>
 
 	PR fortran/42051
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 162870)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -936,11 +936,26 @@ resolve_structure_cons (gfc_expr *expr)
 	      p = gfc_constructor_first (cons->expr->value.constructor);
 	      if (cons->expr->ts.u.cl != p->expr->ts.u.cl)
 		{
-		  gfc_free_expr (cons->expr->ts.u.cl->length);
-		  gfc_free (cons->expr->ts.u.cl);
+		  gfc_charlen *cl, *cl2;
+
+		  cl2 = NULL;
+		  for (cl = gfc_current_ns->cl_list; cl; cl = cl->next)
+		    {
+		      if (cl == cons->expr->ts.u.cl)
+			break;
+		      cl2 = cl;
+		    }
+
+		  gcc_assert (cl);
+
+		  if (cl2)
+		    cl2->next = cl->next;
+
+		  gfc_free_expr (cl->length);
+		  gfc_free (cl);
 		}
 
-	      cons->expr->ts.u.cl = gfc_get_charlen ();
+	      cons->expr->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
 	      cons->expr->ts.u.cl->length_from_typespec = true;
 	      cons->expr->ts.u.cl->length = gfc_copy_expr (comp->ts.u.cl->length);
 	      gfc_resolve_character_array_constructor (cons->expr);


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