Index: runtime/vm/port.cc |
diff --git a/runtime/vm/port.cc b/runtime/vm/port.cc |
index cfb9ac87d5d1bfa700d943ffc46b5012fb0a202b..5a7506852cfe941ece58c05bc03907f0e7813704 100644 |
--- a/runtime/vm/port.cc |
+++ b/runtime/vm/port.cc |
@@ -25,6 +25,14 @@ Random* PortMap::prng_ = NULL; |
intptr_t PortMap::FindPort(Dart_Port port) { |
+ // ILLEGAL_PORT (0) is used as a sentinel value in Entry.port. The loop below |
+ // could return the index to a deleted port when we are searching for |
+ // port id ILLEGAL_PORT. Return -1 immediately to indicate the port |
+ // does not exist. |
+ if (port == ILLEGAL_PORT) { |
+ return -1; |
+ } |
+ ASSERT(port != ILLEGAL_PORT); |
intptr_t index = port % capacity_; |
intptr_t start_index = index; |
Entry entry = map_[index]; |