Use unique_ptr to track ownership of dex files.
Bug: 18809837
Change-Id: Ie571eae8fc19ee9207390cff5c7e2a38071b126a
diff --git a/runtime/dex_file_verifier_test.cc b/runtime/dex_file_verifier_test.cc
index ec1e5f0..00ca8a9 100644
--- a/runtime/dex_file_verifier_test.cc
+++ b/runtime/dex_file_verifier_test.cc
@@ -101,8 +101,9 @@
return dst.release();
}
-static const DexFile* OpenDexFileBase64(const char* base64, const char* location,
- std::string* error_msg) {
+static std::unique_ptr<const DexFile> OpenDexFileBase64(const char* base64,
+ const char* location,
+ std::string* error_msg) {
// decode base64
CHECK(base64 != NULL);
size_t length;
@@ -122,11 +123,11 @@
// read dex file
ScopedObjectAccess soa(Thread::Current());
- std::vector<const DexFile*> tmp;
+ std::vector<std::unique_ptr<const DexFile>> tmp;
bool success = DexFile::Open(location, location, error_msg, &tmp);
CHECK(success) << error_msg;
EXPECT_EQ(1U, tmp.size());
- const DexFile* dex_file = tmp[0];
+ std::unique_ptr<const DexFile> dex_file = std::move(tmp[0]);
EXPECT_EQ(PROT_READ, dex_file->GetPermissions());
EXPECT_TRUE(dex_file->IsReadOnly());
return dex_file;
@@ -166,8 +167,9 @@
header->checksum_ = adler_checksum;
}
-static const DexFile* FixChecksumAndOpen(uint8_t* bytes, size_t length, const char* location,
- std::string* error_msg) {
+static std::unique_ptr<const DexFile> FixChecksumAndOpen(uint8_t* bytes, size_t length,
+ const char* location,
+ std::string* error_msg) {
// Check data.
CHECK(bytes != nullptr);
@@ -187,12 +189,12 @@
// read dex file
ScopedObjectAccess soa(Thread::Current());
- std::vector<const DexFile*> tmp;
+ std::vector<std::unique_ptr<const DexFile>> tmp;
if (!DexFile::Open(location, location, error_msg, &tmp)) {
return nullptr;
}
EXPECT_EQ(1U, tmp.size());
- const DexFile* dex_file = tmp[0];
+ std::unique_ptr<const DexFile> dex_file = std::move(tmp[0]);
EXPECT_EQ(PROT_READ, dex_file->GetPermissions());
EXPECT_TRUE(dex_file->IsReadOnly());
return dex_file;