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

Unified Diff: runtime/platform/hashmap.cc

Issue 2533303005: VM: Fix memory leak during shutdown (Closed)
Patch Set: Simplify socket.cc by not updating hashmaps during shutdown 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
« no previous file with comments | « 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..4d4b4774dd362a8e3c866f00c49c9abb6de84678 100644
--- a/runtime/platform/hashmap.cc
+++ b/runtime/platform/hashmap.cc
@@ -106,11 +106,27 @@ 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;
occupancy_--;
}
+HashMap::Entry* HashMap::Remove(Entry* entry) {
+ Remove(entry->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();
@@ -118,7 +134,6 @@ void HashMap::Clear(ClearFun clear) {
if ((clear != NULL) && (p->key != NULL)) {
clear(p->value);
}
- p->value = NULL;
p->key = NULL;
}
occupancy_ = 0;
« no previous file with comments | « runtime/platform/hashmap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698