Fix memory leak in JDWP object registry
Deletes ObjectRegistryEntry objects before clearing the maps.
Change-Id: Iaa30941fb8768b7294366a8f9855580cb29dadf5
diff --git a/runtime/jdwp/object_registry.cc b/runtime/jdwp/object_registry.cc
index d637a94..29d3c8a 100644
--- a/runtime/jdwp/object_registry.cc
+++ b/runtime/jdwp/object_registry.cc
@@ -115,12 +115,13 @@
// Delete all the JNI references.
JNIEnv* env = self->GetJniEnv();
for (const auto& pair : object_to_entry_) {
- const ObjectRegistryEntry& entry = *pair.second;
- if (entry.jni_reference_type == JNIWeakGlobalRefType) {
- env->DeleteWeakGlobalRef(entry.jni_reference);
+ const ObjectRegistryEntry* entry = pair.second;
+ if (entry->jni_reference_type == JNIWeakGlobalRefType) {
+ env->DeleteWeakGlobalRef(entry->jni_reference);
} else {
- env->DeleteGlobalRef(entry.jni_reference);
+ env->DeleteGlobalRef(entry->jni_reference);
}
+ delete entry;
}
// Clear the maps.
object_to_entry_.clear();