Fix ownership of DexFile in profman
Don't leak the DexFiles we open in profman.
Bug: 34929204
Test: make test-art-host
Change-Id: Ife29556117c4dd84dd3e970901a7fdf458e5ad98
diff --git a/profman/profman.cc b/profman/profman.cc
index ffebb6a..b0cbed1 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -248,8 +248,11 @@
return result;
}
- int DumpOneProfile(const std::string& banner, const std::string& filename, int fd,
- const std::vector<const DexFile*>* dex_files, std::string* dump) {
+ int DumpOneProfile(const std::string& banner,
+ const std::string& filename,
+ int fd,
+ const std::vector<std::unique_ptr<const DexFile>>* dex_files,
+ std::string* dump) {
if (!filename.empty()) {
fd = open(filename.c_str(), O_RDWR);
if (fd < 0) {
@@ -277,7 +280,7 @@
// Open apk/zip files and and read dex files.
MemMap::Init(); // for ZipArchive::OpenFromFd
- std::vector<const DexFile*> dex_files;
+ std::vector<std::unique_ptr<const DexFile>> dex_files;
assert(dex_locations_.size() == apks_fd_.size());
static constexpr bool kVerifyChecksum = true;
for (size_t i = 0; i < dex_locations_.size(); ++i) {
@@ -293,7 +296,7 @@
continue;
}
for (std::unique_ptr<const DexFile>& dex_file : dex_files_for_location) {
- dex_files.push_back(dex_file.release());
+ dex_files.emplace_back(std::move(dex_file));
}
}