Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Unified Diff: runtime/platform/hashmap.cc

Issue 2533303005: VM: Fix memory leak during shutdown (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« runtime/bin/socket.cc ('K') | « runtime/platform/hashmap.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/hashmap.cc
diff --git a/runtime/platform/hashmap.cc b/runtime/platform/hashmap.cc
index 461153398129a270433f45682ffd8f0765885a91..999e511e145d4ad5e83fb95b4c4289829594db5a 100644
--- a/runtime/platform/hashmap.cc
+++ b/runtime/platform/hashmap.cc
@@ -107,10 +107,32 @@ void HashMap::Remove(void* key, uint32_t hash) {
// Clear the candidate which will not break searching the hash table.
candidate->key = NULL;
candidate->value = NULL;
+ candidate->hash = 0;
Florian Schneider 2016/11/30 18:08:41 Why clear the hash code?
kustermann 2016/11/30 21:27:15 For consistency: The [key] *needs* to be cleared
Florian Schneider 2016/11/30 21:51:48 Agree, on the other hand, it may be useful to exam
occupancy_--;
}
+HashMap::Entry* HashMap::Remove(Entry* entry) {
+ // Save the key of the entry we would like to remove, since the removal itself
+ // might do a left-rotation of elements following this one, thereby overriding
+ // `entry`.
+ void* key = entry->key;
Florian Schneider 2016/11/30 18:08:41 Where is the saved key used after calling Remove?
kustermann 2016/11/30 21:27:15 Sorry that was a left-over. The indication whether
+ Remove(key, entry->hash);
+
+ // A key can only exist once in the map and we just removed `key`. This means
+ // that either a left-rotation has happened (in which case `entry` points
+ // already to the next element (in terms of iteration order)) or alternatively
+ // we can use the normal `Next()` call to move in iteration order.
+ if (entry->key != NULL) {
+ // A left-rotation happened. `entry` points already to the next element in
+ // iteration order.
+ return entry;
+ } else {
+ return Next(entry);
+ }
+}
+
+
void HashMap::Clear(ClearFun clear) {
// Mark all entries as empty.
const Entry* end = map_end();
@@ -120,6 +142,7 @@ void HashMap::Clear(ClearFun clear) {
}
p->value = NULL;
p->key = NULL;
+ p->hash = 0;
Florian Schneider 2016/11/30 18:08:41 Same here. Seems wasted work.
kustermann 2016/11/30 21:27:15 Same answer.
}
occupancy_ = 0;
}
« runtime/bin/socket.cc ('K') | « runtime/platform/hashmap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698