Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision e0323a238ee2dc0c70557f1cae4fd4fb3899b3bf)
+++ src/InitTweak/FixInit.cc	(revision 39786813d1b812a2b0e3ca3ae671aed9cd5eea24)
@@ -10,5 +10,5 @@
 // Created On       : Wed Jan 13 16:29:30 2016
 // Last Modified By : Rob Schluntz
-// Last Modified On : Thu Mar 31 10:08:49 2016
+// Last Modified On : Thu Mar 31 13:54:58 2016
 // Update Count     : 30
 //
@@ -38,7 +38,10 @@
 
 		virtual CompoundStmt * mutate( CompoundStmt * compoundStmt );
+		virtual Statement * mutate( ReturnStmt * returnStmt );
+		virtual Statement * mutate( BranchStmt * branchStmt );
 
 	  private:
-		std::list< Statement * > dtorStmts;
+		// stack of list of statements - used to differentiate scopes
+		std::list< std::list< Statement * > > dtorStmts;
 	};
 
@@ -103,5 +106,5 @@
 				} else {
 					stmtsToAddAfter.push_back( ctor );
-					dtorStmts.push_front( ctorInit->get_dtor() );
+					dtorStmts.back().push_front( ctorInit->get_dtor() );
 				}
 				objDecl->set_init( NULL );
@@ -120,14 +123,7 @@
 	}
 
-	CompoundStmt * FixInit::mutate( CompoundStmt * compoundStmt ) {
-		// mutate statements - this will also populate dtorStmts list
-		// don't want to dump all destructors when block is left,
-		// just the destructors associated with variables defined in this block
-		std::list< Statement * > oldDestructorStmts = dtorStmts;
-		dtorStmts = std::list<Statement *>();
-
-		compoundStmt = PolyMutator::mutate( compoundStmt );
-		std::list< Statement * > & statements = compoundStmt->get_kids();
-		for ( std::list< Statement * >::iterator it = dtorStmts.begin(); it != dtorStmts.end(); ++it ) {
+	template<typename Iterator, typename OutputIterator>
+	void insertDtors( Iterator begin, Iterator end, OutputIterator out ) {
+		for ( Iterator it = begin ; it != end ; ++it ) {
 			// remove if instrinsic destructor statement
 			// xxx - test user manually calling intrinsic functions - what happens?
@@ -140,20 +136,60 @@
 				// will call all member dtors, and some members may have a user defined dtor.
 				if ( function->get_var()->get_linkage() == LinkageSpec::Intrinsic ) {
-					// don't ned to call intrinsic dtor, because it does nothing
-					delete *it;
+					// don't need to call intrinsic dtor, because it does nothing
 				} else {
 					// non-intrinsic dtors must be called
-					statements.push_back( *it );
+					*out++ = (*it)->clone();
 				}
 			} else {
 				// could also be a compound statement with a loop, in the case of an array
-				statements.push_back( *it );
+				*out++ = (*it)->clone();
 			}
 		}
+	}
+
+
+	CompoundStmt * FixInit::mutate( CompoundStmt * compoundStmt ) {
+		// mutate statements - this will also populate dtorStmts list.
+		// don't want to dump all destructors when block is left,
+		// just the destructors associated with variables defined in this block,
+		// so push a new list to the top of the stack so that we can differentiate scopes
+		dtorStmts.push_back( std::list<Statement *>() );
+
+		compoundStmt = PolyMutator::mutate( compoundStmt );
+		std::list< Statement * > & statements = compoundStmt->get_kids();
+
+		insertDtors( dtorStmts.back().begin(), dtorStmts.back().end(), back_inserter( statements ) );
+
+		deleteAll( dtorStmts.back() );
+		dtorStmts.pop_back();
+		return compoundStmt;
+	}
+
+	Statement * FixInit::mutate( ReturnStmt * returnStmt ) {
+		for ( std::list< std::list< Statement * > >::reverse_iterator list = dtorStmts.rbegin(); list != dtorStmts.rend(); ++list ) {
+			insertDtors( list->begin(), list->end(), back_inserter( stmtsToAdd ) );
+		}
+		return returnStmt;
+	}
+
+	Statement * FixInit::mutate( BranchStmt * branchStmt ) {
 		// TODO: adding to the end of a block isn't sufficient, since
 		// return/break/goto should trigger destructor when block is left.
-		dtorStmts = oldDestructorStmts;
-		return compoundStmt;
-	}
+		switch( branchStmt->get_type() ) {
+			case BranchStmt::Continue:
+			case BranchStmt::Break:
+				insertDtors( dtorStmts.back().begin(), dtorStmts.back().end(), back_inserter( stmtsToAdd ) );
+				break;
+			case BranchStmt::Goto:
+				// xxx
+				// if goto leaves a block, generate dtors for every block it leaves
+				// if goto is in same block but earlier statement, destruct every object that was defined after the statement
+				break;
+			default:
+				assert( false );
+		}
+		return branchStmt;
+	}
+
 
 } // namespace InitTweak
Index: src/main.cc
===================================================================
--- src/main.cc	(revision e0323a238ee2dc0c70557f1cae4fd4fb3899b3bf)
+++ src/main.cc	(revision 39786813d1b812a2b0e3ca3ae671aed9cd5eea24)
@@ -10,5 +10,5 @@
 // Created On       : Fri May 15 23:12:02 2015
 // Last Modified By : Rob Schluntz
-// Last Modified On : Tue Feb 09 13:28:11 2016
+// Last Modified On : Thu Mar 31 14:00:12 2016
 // Update Count     : 200
 //
@@ -330,4 +330,5 @@
 	} // try
 
+	deleteAll( translationUnit );
 	return 0;
 } // main
