Add nullptr check for dex layout when opening the dex file fails.

Bug: 34971122
Test: mm test-art-host
Change-Id: Id486d6ecbcbc85bcb8dd0ccd24df45a1c2c07f43
diff --git a/compiler/oat_writer.cc b/compiler/oat_writer.cc
index bd2c5e3..a16a34b 100644
--- a/compiler/oat_writer.cc
+++ b/compiler/oat_writer.cc
@@ -2266,6 +2266,10 @@
     File* raw_file = oat_dex_file->source_.GetRawFile();
     dex_file = DexFile::OpenDex(raw_file->Fd(), location, /* verify_checksum */ true, &error_msg);
   }
+  if (dex_file == nullptr) {
+    LOG(ERROR) << "Failed to open dex file for layout:" << error_msg;
+    return false;
+  }
   Options options;
   options.output_to_memmap_ = true;
   DexLayout dex_layout(options, profile_compilation_info_, nullptr);