Index: osprey/wgen/wgen_stmt.cxx
===================================================================
--- osprey/wgen/wgen_stmt.cxx	(revision 3730)
+++ osprey/wgen/wgen_stmt.cxx	(working copy)
@@ -2086,6 +2086,31 @@
   --break_continue_info_i;
 } /* WGEN_Expand_Loop */
 
+struct Scope_Cleanup_Save{
+	int low;
+	int high;
+	SCOPE_CLEANUP_INFO *buffer;
+	void allocate(int cap){
+		high = cap;
+		buffer = (SCOPE_CLEANUP_INFO *) 
+			malloc(sizeof(SCOPE_CLEANUP_INFO) * (cap + 1 ));
+		low = high;
+	};
+	void save(SCOPE_CLEANUP_INFO* e){
+		*(buffer+low) = *e;
+		FmtAssert(low >= 0, ("scope cleanup save stack underflow."));
+		low --;
+	};
+	void restore(SCOPE_CLEANUP_INFO * es){
+		int i;
+		for ( i = high; i > low; i--)
+		{
+			*(es + i) = *(buffer + i);
+		}
+		free (buffer);
+		return;
+	};
+};
 void
 WGEN_Expand_Goto (gs_t label)	// KEY VERSION
 {
@@ -2133,16 +2158,20 @@
       	if (*li != *ci) break;
       if (ci!=Current_scope_nest.rend())
       {
+	Scope_Cleanup_Save scs;
+	scs.allocate(scope_cleanup_i);
 	int scope_cleanup_i_save = scope_cleanup_i;
       	i = scope_cleanup_i;
         Is_True(i != -1, ("WGEN_Expand_Goto: scope_cleanup_stack empty"));
         while ((i >= 0) && (scope_cleanup_stack [i].stmt != *ci))
         {
+           scs.save(scope_cleanup_stack+i);
 	   scope_cleanup_i --;
            Maybe_Emit_Cleanup (i, FALSE);
     	   --i;
         }
-        scope_cleanup_i = scope_cleanup_i_save;
+	scs.restore(scope_cleanup_stack);
+	scope_cleanup_i = scope_cleanup_i_save;
         if (i == -1)
         {
 #ifdef FE_GNU_4_2_0
@@ -2294,9 +2323,12 @@
 #endif
 
     int i = scope_cleanup_i;
+    Scope_Cleanup_Save scs;
+    scs.allocate(scope_cleanup_i);
     int scope_cleanup_i_save = scope_cleanup_i;
     while (i != -1) {
 #ifdef KEY
+      scs.save(scope_cleanup_stack+i);
       scope_cleanup_i--;
       Maybe_Emit_Cleanup (i, FALSE);
 #else
@@ -2305,8 +2337,9 @@
 #endif
       --i;
     }
+    scs.restore(scope_cleanup_stack);
+    scope_cleanup_i = scope_cleanup_i_save;
 #ifdef KEY
-    scope_cleanup_i = scope_cleanup_i_save;
     if (emit_exceptions && processing_handler) {
 	HANDLER_INFO hi = handler_stack.top();
 	FmtAssert (hi.scope, ("NULL scope"));
@@ -2404,9 +2437,12 @@
 
     int i = scope_cleanup_i;
     int scope_cleanup_i_save = scope_cleanup_i;
+    Scope_Cleanup_Save scs;
+    scs.allocate(scope_cleanup_i);
     while (i != -1) {
 #ifdef KEY
       scope_cleanup_i--;
+      scs.save(scope_cleanup_stack+i);
       Maybe_Emit_Cleanup (i, FALSE);
 #else
       if (gs_tree_code(scope_cleanup_stack [i].stmt) == GS_CLEANUP_STMT)
@@ -2414,8 +2450,9 @@
 #endif
       --i;
     }
+    scs.restore(scope_cleanup_stack);
+    scope_cleanup_i = scope_cleanup_i_save;
 #ifdef KEY
-    scope_cleanup_i = scope_cleanup_i_save;
     if (emit_exceptions && processing_handler) {
 	HANDLER_INFO hi = handler_stack.top();
 	FmtAssert (hi.scope, ("NULL scope"));
