]> granicus.if.org Git - clang/commitdiff
Fix dumb use-after-free bug introduced in r242868.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 22 Jul 2015 22:51:15 +0000 (22:51 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 22 Jul 2015 22:51:15 +0000 (22:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242960 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ModuleManager.cpp

index 254e8e69da8b068dbbd2ee92b6937fd437ae7b9a..dbdd94549e123da80d392de6cd45b19bd69f2ba0 100644 (file)
@@ -207,6 +207,15 @@ void ModuleManager::removeModules(
   Roots.erase(std::remove_if(Roots.begin(), Roots.end(), IsVictim),
               Roots.end());
 
+  // Remove the modules from the PCH chain.
+  for (auto I = first; I != last; ++I) {
+    if (!(*I)->isModule()) {
+      PCHChain.erase(std::find(PCHChain.begin(), PCHChain.end(), *I),
+                     PCHChain.end());
+      break;
+    }
+  }
+
   // Delete the modules and erase them from the various structures.
   for (ModuleIterator victim = first; victim != last; ++victim) {
     Modules.erase((*victim)->File);
@@ -229,15 +238,6 @@ void ModuleManager::removeModules(
 
   // Remove the modules from the chain.
   Chain.erase(first, last);
-
-  // Also remove them from the PCH chain.
-  for (auto I = first; I != last; ++I) {
-    if (!(*I)->isModule()) {
-      PCHChain.erase(std::find(PCHChain.begin(), PCHChain.end(), *I),
-                     PCHChain.end());
-      break;
-    }
-  }
 }
 
 void