Fix valgrind gtests and memory leaks.
All tests pass other than image_test which passes if some bad reads
are disabled (buzbee working on this).
Change-Id: Ifd6b6e3aed0bc867703b6e818353a9f296609422
diff --git a/runtime/gc/space/valgrind_malloc_space-inl.h b/runtime/gc/space/valgrind_malloc_space-inl.h
index 4b0c8e3..ed97e60 100644
--- a/runtime/gc/space/valgrind_malloc_space-inl.h
+++ b/runtime/gc/space/valgrind_malloc_space-inl.h
@@ -38,9 +38,6 @@
if (obj_with_rdz == nullptr) {
return nullptr;
}
- if (usable_size != nullptr) {
- *usable_size -= 2 * kValgrindRedZoneBytes;
- }
mirror::Object* result = reinterpret_cast<mirror::Object*>(
reinterpret_cast<byte*>(obj_with_rdz) + kValgrindRedZoneBytes);
// Make redzones as no access.
@@ -58,9 +55,6 @@
if (obj_with_rdz == nullptr) {
return nullptr;
}
- if (usable_size != nullptr) {
- *usable_size -= 2 * kValgrindRedZoneBytes;
- }
mirror::Object* result = reinterpret_cast<mirror::Object*>(
reinterpret_cast<byte*>(obj_with_rdz) + kValgrindRedZoneBytes);
// Make redzones as no access.
@@ -73,10 +67,7 @@
size_t ValgrindMallocSpace<S, A>::AllocationSize(mirror::Object* obj, size_t* usable_size) {
size_t result = S::AllocationSize(reinterpret_cast<mirror::Object*>(
reinterpret_cast<byte*>(obj) - kValgrindRedZoneBytes), usable_size);
- if (usable_size != nullptr) {
- *usable_size -= 2 * kValgrindRedZoneBytes;
- }
- return result - 2 * kValgrindRedZoneBytes;
+ return result;
}
template <typename S, typename A>
@@ -84,11 +75,10 @@
void* obj_after_rdz = reinterpret_cast<void*>(ptr);
void* obj_with_rdz = reinterpret_cast<byte*>(obj_after_rdz) - kValgrindRedZoneBytes;
// Make redzones undefined.
- size_t allocation_size =
- AllocationSize(reinterpret_cast<mirror::Object*>(obj_with_rdz), nullptr);
- VALGRIND_MAKE_MEM_UNDEFINED(obj_with_rdz, allocation_size);
- size_t freed = S::Free(self, reinterpret_cast<mirror::Object*>(obj_with_rdz));
- return freed - 2 * kValgrindRedZoneBytes;
+ size_t usable_size = 0;
+ AllocationSize(ptr, &usable_size);
+ VALGRIND_MAKE_MEM_UNDEFINED(obj_with_rdz, usable_size);
+ return S::Free(self, reinterpret_cast<mirror::Object*>(obj_with_rdz));
}
template <typename S, typename A>
@@ -96,6 +86,7 @@
size_t freed = 0;
for (size_t i = 0; i < num_ptrs; i++) {
freed += Free(self, ptrs[i]);
+ ptrs[i] = nullptr;
}
return freed;
}