PATCH: PR fortran/33375: ICE (segfault) gfortran.dg/common_6.f90

H.J. Lu hjl@lucon.org
Tue Jan 8 17:49:00 GMT 2008


We read freed memory when processing common block symbols whose memory
has been freed before when we rejected it.  This patch frees common
tree on syntax error. Tested on Linux/ia32, Linux/Intel64 and
Linux/ia64 without regressions.


H.J.
---
2008-01-08  H.J. Lu  <hongjiu.lu@intel.com>

	PR fortran/33375
	* symbol.c (free_common_tree): Renamed to ...
	(gfc_free_common_tree): This.  Remove static.
	(gfc_free_namespace): Updated.

	* gfortran.h (gfc_free_common_tree): New.

	* match.c (gfc_match_common): Call gfc_free_common_tree () with
	gfc_current_ns->common_root and set gfc_current_ns->common_root
	to NULL on syntax error.

Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c	(revision 131362)
+++ gcc/fortran/symbol.c	(working copy)
@@ -2726,14 +2726,14 @@ gfc_commit_symbol (gfc_symbol *sym)
 /* Recursive function that deletes an entire tree and all the common
    head structures it points to.  */
 
-static void
-free_common_tree (gfc_symtree * common_tree)
+void
+gfc_free_common_tree (gfc_symtree * common_tree)
 {
   if (common_tree == NULL)
     return;
 
-  free_common_tree (common_tree->left);
-  free_common_tree (common_tree->right);
+  gfc_free_common_tree (common_tree->left);
+  gfc_free_common_tree (common_tree->right);
 
   gfc_free (common_tree);
 }  
@@ -2863,7 +2863,7 @@ gfc_free_namespace (gfc_namespace *ns)
 
   free_sym_tree (ns->sym_root);
   free_uop_tree (ns->uop_root);
-  free_common_tree (ns->common_root);
+  gfc_free_common_tree (ns->common_root);
 
   for (cl = ns->cl_list; cl; cl = cl2)
     {
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 131362)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -2137,6 +2137,7 @@ int gfc_symbols_could_alias (gfc_symbol 
 void gfc_undo_symbols (void);
 void gfc_commit_symbols (void);
 void gfc_commit_symbol (gfc_symbol *);
+void gfc_free_common_tree (gfc_symtree *);
 void gfc_free_namespace (gfc_namespace *);
 
 void gfc_symbol_init_2 (void);
Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c	(revision 131362)
+++ gcc/fortran/match.c	(working copy)
@@ -2951,6 +2951,8 @@ done:
   return MATCH_YES;
 
 syntax:
+  gfc_free_common_tree (gfc_current_ns->common_root);
+  gfc_current_ns->common_root = NULL;
   gfc_syntax_error (ST_COMMON);
 
 cleanup:



More information about the Fortran mailing list