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

Unified Diff: runtime/platform/hashmap.cc

Issue 2231123002: Retry: Fixes memory leaks in the eventhandler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove include of <map> Created 4 years, 4 months 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 693367fc74108fbe66920a286f00784e41a32c5d..34f7ea1284f9f48b38890c95496935551556dcd3 100644
--- a/runtime/platform/hashmap.cc
+++ b/runtime/platform/hashmap.cc
@@ -15,7 +15,7 @@ HashMap::HashMap(MatchFun match, uint32_t initial_capacity) {
HashMap::~HashMap() {
- free(map_);
+ delete[] map_;
}
@@ -106,14 +106,19 @@ 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_--;
}
-void HashMap::Clear() {
+void HashMap::Clear(ClearFun clear) {
// Mark all entries as empty.
const Entry* end = map_end();
for (Entry* p = map_; p < end; p++) {
+ if ((clear != NULL) && (p->key != NULL)) {
+ clear(p->value);
+ }
+ p->value = NULL;
p->key = NULL;
}
occupancy_ = 0;
@@ -159,14 +164,14 @@ HashMap::Entry* HashMap::Probe(void* key, uint32_t hash) {
void HashMap::Initialize(uint32_t capacity) {
ASSERT(dart::Utils::IsPowerOfTwo(capacity));
- map_ = reinterpret_cast<Entry*>(malloc(capacity * sizeof(Entry)));
+ map_ = new Entry[capacity];
if (map_ == NULL) {
// TODO(sgjesse): Handle out of memory.
FATAL("Cannot allocate memory for hashmap");
return;
}
capacity_ = capacity;
- Clear();
+ occupancy_ = 0;
}
@@ -186,7 +191,7 @@ void HashMap::Resize() {
}
// Delete old map.
- free(map);
+ delete[] map;
}
} // namespace dart
« 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