OSDN Git Service

ART: Fix unclosed files in dex2oat
authorAndreas Gampe <agampe@google.com>
Wed, 3 Dec 2014 22:28:02 +0000 (14:28 -0800)
committerAndreas Gampe <agampe@google.com>
Wed, 3 Dec 2014 23:24:28 +0000 (15:24 -0800)
Under some error conditions files are not closed, and the close guard
will complain.

Bug: 18603475

(cherry picked from commit d97465c3742cc3c82843665f2678b881de29854b)

Change-Id: I7155e3f4f6231844edd375b9302ecf1ba8079950

dex2oat/dex2oat.cc

index a1ac2f0..25d6db1 100644 (file)
@@ -987,6 +987,12 @@ class Dex2Oat FINAL {
     return true;
   }
 
+  void EraseOatFile() {
+    DCHECK(oat_file_.get() != nullptr);
+    oat_file_->Erase();
+    oat_file_.reset();
+  }
+
   // Set up the environment for compilation. Includes starting the runtime and loading/opening the
   // boot class path.
   bool Setup() {
@@ -1301,7 +1307,6 @@ class Dex2Oat FINAL {
       if (!driver_->WriteElf(android_root_, is_host_, dex_files_, oat_writer.get(),
                              oat_file_.get())) {
         LOG(ERROR) << "Failed to write ELF file " << oat_file_->GetPath();
-        oat_file_->Erase();
         return false;
       }
     }
@@ -1712,6 +1717,7 @@ static int CompileImage(Dex2Oat& dex2oat) {
 
   // Create the boot.oat.
   if (!dex2oat.CreateOatFile()) {
+    dex2oat.EraseOatFile();
     return EXIT_FAILURE;
   }
 
@@ -1756,6 +1762,7 @@ static int CompileApp(Dex2Oat& dex2oat) {
 
   // Create the app oat.
   if (!dex2oat.CreateOatFile()) {
+    dex2oat.EraseOatFile();
     return EXIT_FAILURE;
   }
 
@@ -1813,6 +1820,7 @@ static int dex2oat(int argc, char** argv) {
   LOG(INFO) << CommandLine();
 
   if (!dex2oat.Setup()) {
+    dex2oat.EraseOatFile();
     return EXIT_FAILURE;
   }