OSDN Git Service

Release dummy MemMaps corresponding to dlopen.
authorDavid Srbecky <dsrbecky@google.com>
Wed, 17 Jun 2015 17:36:23 +0000 (18:36 +0100)
committerDavid Srbecky <dsrbecky@google.com>
Wed, 17 Jun 2015 21:52:48 +0000 (22:52 +0100)
This fixes memory leak.

Change-Id: I857f078e8559a56b2d10dd081256c41ab28c8ec6

runtime/oat_file.cc
runtime/oat_file.h

index 225fee0..ad5741e 100644 (file)
@@ -301,15 +301,17 @@ bool OatFile::Dlopen(const std::string& elf_filename, uint8_t* requested_base,
             uint8_t* vaddr = reinterpret_cast<uint8_t*>(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<MemMap>(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<std::unique_ptr<MemMap>>* const dlopen_mmaps_;
+  } context = { begin_, &dlopen_mmaps_ };
 
   if (dl_iterate_phdr(dl_iterate_context::callback, &context) == 0) {
     PrintFileToLog("/proc/self/maps", LogSeverity::WARNING);
index c58b029..1a782de 100644 (file)
@@ -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<std::unique_ptr<MemMap>> dlopen_mmaps_;
+
   // Owning storage for the OatDexFile objects.
   std::vector<const OatDexFile*> oat_dex_files_storage_;