From 09fe1bb696847e6f1b482e5ac40029d53a2402df Mon Sep 17 00:00:00 2001
From: Douglas Gregor <dgregor@apple.com>
Date: Thu, 17 Nov 2011 02:05:44 +0000
Subject: [PATCH] Actually free memory for the module maps

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144880 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/Lex/ModuleMap.h |  4 +++-
 lib/Lex/ModuleMap.cpp         | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/include/clang/Lex/ModuleMap.h b/include/clang/Lex/ModuleMap.h
index e9bf1b35c14..b1eaebddb20 100644
--- a/include/clang/Lex/ModuleMap.h
+++ b/include/clang/Lex/ModuleMap.h
@@ -73,7 +73,9 @@ public:
       : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), 
         UmbrellaHeader(0), IsExplicit(IsExplicit) {
     }
-           
+     
+    ~Module();
+    
     /// \brief Determine whether this module is a submodule.
     bool isSubModule() const { return Parent != 0; }
     
diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp
index 0c51659cab8..393118110af 100644
--- a/lib/Lex/ModuleMap.cpp
+++ b/lib/Lex/ModuleMap.cpp
@@ -31,6 +31,15 @@ using namespace clang;
 // Module
 //----------------------------------------------------------------------------//
 
+ModuleMap::Module::~Module() {
+  for (llvm::StringMap<Module *>::iterator I = SubModules.begin(), 
+                                        IEnd = SubModules.end();
+       I != IEnd; ++I) {
+    delete I->getValue();
+  }
+
+}
+
 std::string ModuleMap::Module::getFullModuleName() const {
   llvm::SmallVector<StringRef, 2> Names;
   
@@ -72,6 +81,12 @@ ModuleMap::ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC) {
 }
 
 ModuleMap::~ModuleMap() {
+  for (llvm::StringMap<Module *>::iterator I = Modules.begin(), 
+                                        IEnd = Modules.end();
+       I != IEnd; ++I) {
+    delete I->getValue();
+  }
+  
   delete SourceMgr;
 }
 
-- 
GitLab