Fix the handful of leaks detectable in our tests.
Change-Id: I74ad1a3831fbebad60ff24f0b3ac07cade823b7a
diff --git a/Android.mk b/Android.mk
index 7ddaa37..7e5555d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -73,7 +73,7 @@
# "mm valgrind-art-host" to build and run all host tests under valgrind.
.PHONY: valgrind-art-host
valgrind-art-host: $(ART_HOST_TEST_DEPENDENCIES)
- $(call run-host-tests-with,"valgrind")
+ $(call run-host-tests-with,valgrind --leak-check=full)
@echo valgrind-art-host PASSED
# "mm tsan-art-host" to build and run all host tests under tsan.
diff --git a/src/common_test.h b/src/common_test.h
index 402766f..a7daba1 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -33,13 +33,13 @@
// decode base64
CHECK(base64 != NULL);
size_t length;
- byte* dex_bytes = DecodeBase64(base64, &length);
- CHECK(dex_bytes != NULL);
+ UniquePtr<byte[]> dex_bytes(DecodeBase64(base64, &length));
+ CHECK(dex_bytes.get() != NULL);
// write to provided file
UniquePtr<File> file(OS::OpenFile(location.c_str(), true));
CHECK(file.get() != NULL);
- if (!file->WriteFully(dex_bytes, length)) {
+ if (!file->WriteFully(dex_bytes.get(), length)) {
PLOG(FATAL) << "Failed to write base64 as dex file";
}
file.reset();
@@ -295,6 +295,7 @@
(*icu_cleanup_fn)();
compiler_.reset();
+ STLDeleteElements(&opened_dex_files_);
Heap::VerifyHeap(); // Check for heap corruption after the test
}
@@ -325,13 +326,13 @@
filename += ".jar";
const DexFile* dex_file = DexFile::Open(filename, "");
CHECK(dex_file != NULL) << "Failed to open " << filename;
+ opened_dex_files_.push_back(dex_file);
return dex_file;
}
ClassLoader* LoadDex(const char* dex_name) {
const DexFile* dex_file = OpenTestDexFile(dex_name);
CHECK(dex_file != NULL);
- loaded_dex_files_.push_back(dex_file);
class_linker_->RegisterDexFile(*dex_file);
std::vector<const DexFile*> class_path;
class_path.push_back(dex_file);
@@ -398,7 +399,7 @@
UniquePtr<Compiler> compiler_;
private:
- std::vector<const DexFile*> loaded_dex_files_;
+ std::vector<const DexFile*> opened_dex_files_;
};
} // namespace art
diff --git a/src/dex_file_test.cc b/src/dex_file_test.cc
index 4b311dc..3cbef15 100644
--- a/src/dex_file_test.cc
+++ b/src/dex_file_test.cc
@@ -10,8 +10,8 @@
class DexFileTest : public CommonTest {};
TEST_F(DexFileTest, Open) {
- UniquePtr<const DexFile> dex(OpenTestDexFile("Nested"));
- ASSERT_TRUE(dex.get() != NULL);
+ const DexFile* dex(OpenTestDexFile("Nested"));
+ ASSERT_TRUE(dex != NULL);
}
// Although this is the same content logically as the Nested test dex,
@@ -70,8 +70,8 @@
}
TEST_F(DexFileTest, ClassDefs) {
- UniquePtr<const DexFile> raw(OpenTestDexFile("Nested"));
- ASSERT_TRUE(raw.get() != NULL);
+ const DexFile* raw(OpenTestDexFile("Nested"));
+ ASSERT_TRUE(raw != NULL);
EXPECT_EQ(2U, raw->NumClassDefs());
const DexFile::ClassDef& c0 = raw->GetClassDef(0);
@@ -82,8 +82,8 @@
}
TEST_F(DexFileTest, CreateMethodSignature) {
- UniquePtr<const DexFile> raw(OpenTestDexFile("CreateMethodSignature"));
- ASSERT_TRUE(raw.get() != NULL);
+ const DexFile* raw(OpenTestDexFile("CreateMethodSignature"));
+ ASSERT_TRUE(raw != NULL);
EXPECT_EQ(1U, raw->NumClassDefs());
const DexFile::ClassDef& class_def = raw->GetClassDef(0);
@@ -91,7 +91,7 @@
const byte* class_data = raw->GetClassData(class_def);
ASSERT_TRUE(class_data != NULL);
- ClassDataItemIterator it(*raw.get(), class_data);
+ ClassDataItemIterator it(*raw, class_data);
EXPECT_EQ(1u, it.NumDirectMethods());
@@ -137,8 +137,8 @@
}
TEST_F(DexFileTest, FindStringId) {
- UniquePtr<const DexFile> raw(OpenTestDexFile("CreateMethodSignature"));
- ASSERT_TRUE(raw.get() != NULL);
+ const DexFile* raw(OpenTestDexFile("CreateMethodSignature"));
+ ASSERT_TRUE(raw != NULL);
EXPECT_EQ(1U, raw->NumClassDefs());
const char* strings[] = { "LCreateMethodSignature;", "Ljava/lang/Float;", "Ljava/lang/Object;",
diff --git a/src/heap.cc b/src/heap.cc
index 1efc956..ba52a54 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -151,14 +151,10 @@
// all daemon threads are suspended, and we also know that the threads list have been deleted, so
// those threads can't resume. We're the only running thread, and we can do whatever we like...
STLDeleteElements(&spaces_);
- if (mark_bitmap_ != NULL) {
- delete mark_bitmap_;
- mark_bitmap_ = NULL;
- }
- if (live_bitmap_ != NULL) {
- delete live_bitmap_;
- }
- live_bitmap_ = NULL;
+ delete mark_bitmap_;
+ delete live_bitmap_;
+ delete card_table_;
+ delete lock_;
}
Object* Heap::AllocObject(Class* klass, size_t byte_count) {
diff --git a/src/runtime.cc b/src/runtime.cc
index c6081ff..904d959 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -12,6 +12,7 @@
#include "class_linker.h"
#include "class_loader.h"
#include "debugger.h"
+#include "dex_verifier.h"
#include "heap.h"
#include "image.h"
#include "intern_table.h"
@@ -73,6 +74,7 @@
delete class_linker_;
Heap::Destroy();
+ verifier::DexVerifier::DeleteGcMaps();
delete intern_table_;
delete java_vm_;
Thread::Shutdown();