From: Richard Smith Date: Wed, 22 Jul 2015 22:51:15 +0000 (+0000) Subject: Fix dumb use-after-free bug introduced in r242868. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f385fa0e26474569205e6fdef3fb7c4a0c955da;p=clang Fix dumb use-after-free bug introduced in r242868. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242960 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ModuleManager.cpp b/lib/Serialization/ModuleManager.cpp index 254e8e69da..dbdd94549e 100644 --- a/lib/Serialization/ModuleManager.cpp +++ b/lib/Serialization/ModuleManager.cpp @@ -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