Make it extra safe when deleting a turn entry.
Check if it is in the list of turn entries before attempting to delete it.
BUG=
Review URL: https://codereview.webrtc.org/1458013004
Cr-Commit-Position: refs/heads/master@{#10877}
diff --git a/webrtc/p2p/base/turnport.cc b/webrtc/p2p/base/turnport.cc
index 20c2b60..be581ed 100644
--- a/webrtc/p2p/base/turnport.cc
+++ b/webrtc/p2p/base/turnport.cc
@@ -907,6 +907,11 @@
return (it != entries_.end()) ? *it : NULL;
}
+bool TurnPort::EntryExists(TurnEntry* e) {
+ auto it = std::find(entries_.begin(), entries_.end(), e);
+ return it != entries_.end();
+}
+
void TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr) {
TurnEntry* entry = FindEntry(addr);
if (entry == nullptr) {
@@ -928,6 +933,9 @@
void TurnPort::DestroyEntryIfNotCancelled(TurnEntry* entry,
uint32_t timestamp) {
+ if (!EntryExists(entry)) {
+ return;
+ }
bool cancelled = timestamp != entry->destruction_timestamp();
if (!cancelled) {
DestroyEntry(entry);
diff --git a/webrtc/p2p/base/turnport.h b/webrtc/p2p/base/turnport.h
index 0cdc291..62e3c41 100644
--- a/webrtc/p2p/base/turnport.h
+++ b/webrtc/p2p/base/turnport.h
@@ -218,6 +218,7 @@
bool HasPermission(const rtc::IPAddress& ipaddr) const;
TurnEntry* FindEntry(const rtc::SocketAddress& address) const;
TurnEntry* FindEntry(int channel_id) const;
+ bool EntryExists(TurnEntry* e);
void CreateOrRefreshEntry(const rtc::SocketAddress& address);
void DestroyEntry(TurnEntry* entry);
// Destroys the entry only if |timestamp| matches the destruction timestamp