diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index dbafc449cc9c08af0a72c20e358a927d187402bc..69c0fe8e5e67bf63f0e0a768ed9ba23b42fce225 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+2012-09-05  Tobias Burnus  <burnus@net-b.de>
+
+	PR fortran/54462
+	* symbol.c (gfc_undo_symbols): Avoid NULL pointer dereference.
+
 2012-09-04  Janus Weil  <janus@gcc.gnu.org>
 
 	PR fortran/54435
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 8d3b56c9569557332b4b92b66b9ca0c1df87696a..1f4a73526865c33b24f8dee9348cd992588b1cee 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -2919,10 +2919,12 @@ gfc_undo_symbols (void)
 		  gfc_symtree st, *st0;
 		  st0 = find_common_symtree (p->ns->common_root,
 					     p->common_block);
-
-		  st.name = st0->name;
-		  gfc_delete_bbt (&p->ns->common_root, &st, compare_symtree);
-		  free (st0);
+		  if (st0)
+		    {
+		      st.name = st0->name;
+		      gfc_delete_bbt (&p->ns->common_root, &st, compare_symtree);
+		      free (st0);
+		    }
 		}
 
 	      if (p->common_block->head == p)