Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision 1e8b02f5d6be0872e21934bb090b99f373442fd9)
+++ src/SymTab/Validate.cc	(revision 46f61345ffd40c8a09b489da6e3b288fbf479cdf)
@@ -49,4 +49,5 @@
 #include "SynTree/Statement.h"
 #include "SynTree/TypeSubstitution.h"
+#include "GenPoly/ScopedMap.h"
 #include "Indexer.h"
 #include "FixFunction.h"
@@ -162,5 +163,6 @@
 		void addImplicitTypedef( AggDecl * aggDecl );
 
-		typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
+		typedef std::unique_ptr<TypedefDecl> TypedefDeclPtr;
+		typedef GenPoly::ScopedMap< std::string, std::pair< TypedefDeclPtr, int > > TypedefMap;
 		typedef std::map< std::string, TypeDecl * > TypeDeclMap;
 		TypedefMap typedefNames;
@@ -549,5 +551,5 @@
 			}
 		} else {
-			typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
+			typedefNames[ tyDecl->get_name() ] = std::make_pair( TypedefDeclPtr( tyDecl ), scopeLevel );
 		} // if
 
@@ -567,5 +569,5 @@
 			return new EnumDecl( enumDecl->get_name() );
 		} else {
-			return ret;
+			return ret->clone();
 		} // if
 	}
@@ -582,14 +584,14 @@
 
 	DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {
-		TypedefMap oldNames = typedefNames;
+		typedefNames.beginScope();
 		DeclarationWithType *ret = Mutator::mutate( funcDecl );
-		typedefNames = oldNames;
+		typedefNames.endScope();
 		return ret;
 	}
 
 	DeclarationWithType *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
-		TypedefMap oldNames = typedefNames;
+		typedefNames.beginScope();
 		DeclarationWithType *ret = Mutator::mutate( objDecl );
-		typedefNames = oldNames;
+		typedefNames.endScope();
 		// is the type a function?
 		if ( FunctionType *funtype = dynamic_cast<FunctionType *>( ret->get_type() ) ) {
@@ -603,12 +605,12 @@
 
 	Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {
-		TypedefMap oldNames = typedefNames;
+		typedefNames.beginScope();
 		Expression *ret = Mutator::mutate( castExpr );
-		typedefNames = oldNames;
+		typedefNames.endScope();
 		return ret;
 	}
 
 	CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {
-		TypedefMap oldNames = typedefNames;
+		typedefNames.beginScope();
 		scopeLevel += 1;
 		CompoundStmt *ret = Mutator::mutate( compoundStmt );
@@ -625,5 +627,5 @@
 			i = next;
 		} // while
-		typedefNames = oldNames;
+		typedefNames.endScope();
 		return ret;
 	}
@@ -656,6 +658,6 @@
 				type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
 			} // if
-			TypedefDecl * tyDecl = new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type );
-			typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
+			TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type ) );
+			typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );
 		} // if
 	}
