diff options
-rw-r--r-- | dex2oat/linker/oat_writer.cc | 4 | ||||
-rw-r--r-- | runtime/oat/oat.cc | 8 | ||||
-rw-r--r-- | runtime/oat/oat.h | 1 | ||||
-rw-r--r-- | runtime/oat/oat_file.cc | 4 | ||||
-rw-r--r-- | runtime/runtime_image.cc | 5 |
5 files changed, 14 insertions, 8 deletions
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc index c79dda3d8d..7415604ab6 100644 --- a/dex2oat/linker/oat_writer.cc +++ b/dex2oat/linker/oat_writer.cc @@ -655,9 +655,7 @@ void OatWriter::PrepareLayout(MultiOatRelativePatcher* relative_patcher) { } OatWriter::~OatWriter() { - if (oat_header_ != nullptr) { - operator delete (oat_header_, oat_header_->GetHeaderSize()); - } + OatHeader::Delete(oat_header_); } class OatWriter::DexMethodVisitor { diff --git a/runtime/oat/oat.cc b/runtime/oat/oat.cc index 1136458c28..9a5dd9dfdf 100644 --- a/runtime/oat/oat.cc +++ b/runtime/oat/oat.cc @@ -61,6 +61,14 @@ OatHeader* OatHeader::Create(InstructionSet instruction_set, base_oat_offset); } +void OatHeader::Delete(OatHeader* header) { + if (header != nullptr) { + size_t size = header->GetHeaderSize(); + header->~OatHeader(); + operator delete(header, size); + } +} + OatHeader::OatHeader(InstructionSet instruction_set, const InstructionSetFeatures* instruction_set_features, uint32_t dex_file_count, diff --git a/runtime/oat/oat.h b/runtime/oat/oat.h index 445f088d17..53f9497d1f 100644 --- a/runtime/oat/oat.h +++ b/runtime/oat/oat.h @@ -68,6 +68,7 @@ class EXPORT PACKED(4) OatHeader { uint32_t dex_file_count, const SafeMap<std::string, std::string>* variable_data, uint32_t base_oat_offset = 0u); + static void Delete(OatHeader* header); bool IsValid() const; std::string GetValidationErrorMessage() const; diff --git a/runtime/oat/oat_file.cc b/runtime/oat/oat_file.cc index 6679d23aff..c5b53b7021 100644 --- a/runtime/oat/oat_file.cc +++ b/runtime/oat/oat_file.cc @@ -1690,9 +1690,7 @@ class OatFileBackedByVdex final : public OatFileBase { oat_header_(nullptr) {} ~OatFileBackedByVdex() { - if (oat_header_ != nullptr) { - operator delete (oat_header_, oat_header_->GetHeaderSize()); - } + OatHeader::Delete(oat_header_); } static OatFileBackedByVdex* Open(const std::vector<const DexFile*>& dex_files, diff --git a/runtime/runtime_image.cc b/runtime/runtime_image.cc index 1d3007ad3a..28f311a6f9 100644 --- a/runtime/runtime_image.cc +++ b/runtime/runtime_image.cc @@ -1138,11 +1138,12 @@ class RuntimeImageHelper { std::unique_ptr<const InstructionSetFeatures> isa_features = InstructionSetFeatures::FromCppDefines(); - std::unique_ptr<OatHeader> oat_header( + std::unique_ptr<OatHeader, decltype(&OatHeader::Delete)> oat_header( OatHeader::Create(kRuntimeQuickCodeISA, isa_features.get(), number_of_dex_files, - &key_value_store)); + &key_value_store), + &OatHeader::Delete); // Create the byte array containing the oat header and dex checksums. uint32_t checksums_size = checksums.size() * sizeof(uint32_t); |