2nd try to fix leakage of the module provider. note that moduleprovider takes ownership of the module

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58128 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/Backend.cpp b/Driver/Backend.cpp
index 37c5f16..98cfeea 100644
--- a/Driver/Backend.cpp
+++ b/Driver/Backend.cpp
@@ -91,7 +91,6 @@
 
       delete AsmOutStream;
       delete TheTargetData;
-      delete TheModule;
       delete ModuleProvider;
       delete CodeGenPasses;
       delete PerModulePasses;
@@ -102,6 +101,7 @@
       Gen->InitializeTU(TU);
 
       TheModule = Gen->GetModule();
+      ModuleProvider = new ExistingModuleProvider(TheModule);
       TheTargetData = 
         new llvm::TargetData(TU.getContext().Target.getTargetDescription());
     }
@@ -122,7 +122,6 @@
 
 FunctionPassManager *BackendConsumer::getCodeGenPasses() const {
   if (!CodeGenPasses) {
-    ModuleProvider = new ExistingModuleProvider(TheModule);
     CodeGenPasses = new FunctionPassManager(ModuleProvider);
     CodeGenPasses->add(new TargetData(*TheTargetData));
   }
@@ -141,8 +140,7 @@
 
 FunctionPassManager *BackendConsumer::getPerFunctionPasses() const {
   if (!PerFunctionPasses) {
-    PerFunctionPasses = 
-      new FunctionPassManager(new ExistingModuleProvider(TheModule));
+    PerFunctionPasses = new FunctionPassManager(ModuleProvider);
     PerFunctionPasses->add(new TargetData(*TheTargetData));
   }