Index: components/mus/ws/display_manager.cc |
diff --git a/components/mus/ws/display_manager.cc b/components/mus/ws/display_manager.cc |
index b5dbb0953a20e1de6910c3855c59cdaa4a4f16ec..15a91609f906d549bc1abf84f93de35330e46ce8 100644 |
--- a/components/mus/ws/display_manager.cc |
+++ b/components/mus/ws/display_manager.cc |
@@ -41,13 +41,19 @@ void DisplayManager::AddDisplay(Display* display) { |
void DisplayManager::DestroyDisplay(Display* display) { |
if (pending_displays_.count(display)) { |
pending_displays_.erase(display); |
- } else { |
+ } else if (displays_.count(display)) { |
for (const auto& pair : user_display_managers_) |
pair.second->OnWillDestroyDisplay(display); |
- |
- DCHECK(displays_.count(display)); |
displays_.erase(display); |
+ } else { |
+ // NOTE: This may fuction may be re-entered with the same |display| in which |
+ // case we need to avoid a double-free. This should probably be considered a |
+ // bug. This was hidden before due to the fact that the mus app exited |
+ // uncleanly in tests. |
+ DLOG(WARNING) << "Trying to destroy the same display twice."; |
+ return; |
} |
+ |
delete display; |
// If we have no more roots left, let the app know so it can terminate. |