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

Unified Diff: runtime/bin/eventhandler.h

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 | « no previous file | runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/eventhandler.h
diff --git a/runtime/bin/eventhandler.h b/runtime/bin/eventhandler.h
index ab5b590b65112c7cb28643df413ff7be28d3aae1..44b5ec834b137a8d2466f3e9a61a7c70152a3f45 100644
--- a/runtime/bin/eventhandler.h
+++ b/runtime/bin/eventhandler.h
@@ -132,6 +132,8 @@ class CircularLinkedList {
public:
CircularLinkedList() : head_(NULL) {}
+ typedef void (*ClearFun) (void* value);
+
// Returns true if the list was empty.
bool Add(T t) {
Entry* e = new Entry(t);
@@ -151,7 +153,7 @@ class CircularLinkedList {
}
}
- void RemoveHead() {
+ void RemoveHead(ClearFun clear = NULL) {
ASSERT(head_ != NULL);
Entry* e = head_;
@@ -162,6 +164,9 @@ class CircularLinkedList {
e->next_->prev_ = e->prev_;
head_ = e->next_;
}
+ if (clear != NULL) {
+ clear(reinterpret_cast<void*>(e->t));
+ }
delete e;
}
@@ -195,9 +200,9 @@ class CircularLinkedList {
}
}
- void RemoveAll() {
+ void RemoveAll(ClearFun clear = NULL) {
while (HasHead()) {
- RemoveHead();
+ RemoveHead(clear);
}
}
@@ -413,7 +418,9 @@ class DescriptorInfoMultipleMixin : public DI {
: DI(fd), tokens_map_(&SamePortValue, kTokenCount),
disable_tokens_(disable_tokens) {}
- virtual ~DescriptorInfoMultipleMixin() {}
+ virtual ~DescriptorInfoMultipleMixin() {
+ RemoveAllPorts();
+ }
virtual bool IsListeningSocket() const { return true; }
@@ -497,14 +504,16 @@ class DescriptorInfoMultipleMixin : public DI {
}
virtual void RemoveAllPorts() {
- active_readers_.RemoveAll();
for (HashMap::Entry *entry = tokens_map_.Start();
entry != NULL;
entry = tokens_map_.Next(entry)) {
PortEntry* pentry = reinterpret_cast<PortEntry*>(entry->value);
+ entry->value = NULL;
+ active_readers_.Remove(pentry);
delete pentry;
}
tokens_map_.Clear();
+ active_readers_.RemoveAll(DeletePortEntry);
}
virtual Dart_Port NextNotifyDartPort(intptr_t events_ready) {
@@ -585,6 +594,11 @@ class DescriptorInfoMultipleMixin : public DI {
}
private:
+ static void DeletePortEntry(void* data) {
+ PortEntry* entry = reinterpret_cast<PortEntry*>(data);
+ delete entry;
+ }
+
// The [Dart_Port]s which are not paused (i.e. are interested in read events,
// i.e. `mask == (1 << kInEvent)`) and we have enough tokens to communicate
// with them.
« no previous file with comments | « no previous file | runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698