Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision 35b1bf4a3c6817f25d0e553e86d13309a28c2b42)
+++ src/InitTweak/FixInit.cc	(revision 52c14b38a7806747cf75c7dbf3ad4e40b240a03f)
@@ -104,4 +104,8 @@
 			virtual void visit( CompoundStmt *compoundStmt ) override;
 			virtual void visit( DeclStmt *stmt ) override;
+
+			// don't go into other functions
+			virtual void visit( FunctionDecl *decl ) override {}
+
 		  protected:
 			ObjectSet curVars;
@@ -166,9 +170,10 @@
 			typedef std::list< OrderedDecls > OrderedDeclsStack;
 
-			InsertDtors( LabelFinder & finder ) : labelVars( finder.vars ) {}
+			InsertDtors( LabelFinder & finder ) : finder( finder ), labelVars( finder.vars ) {}
 
 			using Parent::visit;
 
 			virtual void visit( ObjectDecl * objDecl ) override;
+			virtual void visit( FunctionDecl * funcDecl ) override;
 
 			virtual void visit( CompoundStmt * compoundStmt ) override;
@@ -178,4 +183,5 @@
 			void handleGoto( BranchStmt * stmt );
 
+			LabelFinder & finder;
 			LabelFinder::LabelMap & labelVars;
 			OrderedDeclsStack reverseDeclOrder;
@@ -318,5 +324,4 @@
 			LabelFinder finder;
 			InsertDtors inserter( finder );
-			acceptAll( translationUnit, finder );
 			acceptAll( translationUnit, inserter );
 		}
@@ -778,5 +783,5 @@
 		}
 
-		void ObjDeclCollector::visit( CompoundStmt *compoundStmt ) {
+		void ObjDeclCollector::visit( CompoundStmt * compoundStmt ) {
 			std::set< ObjectDecl * > prevVars = curVars;
 			Parent::visit( compoundStmt );
@@ -784,5 +789,5 @@
 		}
 
-		void ObjDeclCollector::visit( DeclStmt *stmt ) {
+		void ObjDeclCollector::visit( DeclStmt * stmt ) {
 			// keep track of all variables currently in scope
 			if ( ObjectDecl * objDecl = dynamic_cast< ObjectDecl * > ( stmt->get_decl() ) ) {
@@ -828,4 +833,22 @@
 			} // if
 			Parent::visit( objDecl );
+		}
+
+		template< typename Visitor >
+		void handleFuncDecl( FunctionDecl * funcDecl, Visitor & visitor ) {
+			maybeAccept( funcDecl->get_functionType(), visitor );
+			acceptAll( funcDecl->get_oldDecls(), visitor );
+			maybeAccept( funcDecl->get_statements(), visitor );
+		}
+
+		void InsertDtors::visit( FunctionDecl * funcDecl ) {
+			// each function needs to have its own set of labels
+			ValueGuard< LabelFinder::LabelMap > oldLabels( labelVars );
+			labelVars.clear();
+			handleFuncDecl( funcDecl, finder );
+
+			// all labels for this function have been collected, insert destructors as appropriate.
+			// can't be Parent::mutate, because ObjDeclCollector bottoms out on FunctionDecl
+			handleFuncDecl( funcDecl, *this );
 		}
 
