Keep the onwership of TargetData.  Dont give it to CodeGenPasses.
diff --git a/lib/ExecutionEngine/Compiler.cpp b/lib/ExecutionEngine/Compiler.cpp
index 37cb8e1..c3b4a4a 100644
--- a/lib/ExecutionEngine/Compiler.cpp
+++ b/lib/ExecutionEngine/Compiler.cpp
@@ -523,7 +523,7 @@
 #if CLASSIC_JIT
   // Create code-gen pass to run the code emitter
   CodeGenPasses = new llvm::FunctionPassManager(mModule);
-  CodeGenPasses->add(TD);  // Will take the ownership of TD
+  CodeGenPasses->add(new llvm::TargetData(*TD));
 
   if (TM->addPassesToEmitMachineCode(*CodeGenPasses,
                                      *mCodeEmitter,
@@ -671,11 +671,15 @@
   // LOGE("on_bcc_compiler_error");
   if (CodeGenPasses) {
     delete CodeGenPasses;
-  } else if (TD) {
+  }
+
+  if (TD) {
     delete TD;
   }
-  if (TM)
+
+  if (TM) {
     delete TM;
+  }
 
   if (mError.empty()) {
     return 0;