From 82e73dcc290ae8603c8a2e533d6a8a19cc2983a3 Mon Sep 17 00:00:00 2001 From: David Srbecky Date: Wed, 17 Jun 2015 18:36:23 +0100 Subject: [PATCH] Release dummy MemMaps corresponding to dlopen. This fixes memory leak. Change-Id: I857f078e8559a56b2d10dd081256c41ab28c8ec6 --- runtime/oat_file.cc | 8 +++++--- runtime/oat_file.h | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index 225fee0a6..ad5741e47 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -301,15 +301,17 @@ bool OatFile::Dlopen(const std::string& elf_filename, uint8_t* requested_base, uint8_t* vaddr = reinterpret_cast(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr); size_t memsz = info->dlpi_phdr[i].p_memsz; - MemMap::MapDummy(info->dlpi_name, vaddr, memsz); + MemMap* mmap = MemMap::MapDummy(info->dlpi_name, vaddr, memsz); + context->dlopen_mmaps_->push_back(std::unique_ptr(mmap)); } } return 1; // Stop iteration and return 1 from dl_iterate_phdr. } return 0; // Continue iteration and return 0 from dl_iterate_phdr when finished. } - const uint8_t* begin_; - } context = { begin_ }; + const uint8_t* const begin_; + std::vector>* const dlopen_mmaps_; + } context = { begin_, &dlopen_mmaps_ }; if (dl_iterate_phdr(dl_iterate_context::callback, &context) == 0) { PrintFileToLog("/proc/self/maps", LogSeverity::WARNING); diff --git a/runtime/oat_file.h b/runtime/oat_file.h index c58b0294c..1a782deb8 100644 --- a/runtime/oat_file.h +++ b/runtime/oat_file.h @@ -321,6 +321,9 @@ class OatFile FINAL { // dlopen handle during runtime. void* dlopen_handle_; + // Dummy memory map objects corresponding to the regions mapped by dlopen. + std::vector> dlopen_mmaps_; + // Owning storage for the OatDexFile objects. std::vector oat_dex_files_storage_; -- 2.11.0