]> khamidou — GitHub mirrors - electron.git/commitdiff
Guard against bad events in screen module
authorCheng Zhao <zcbenz@gmail.com>
Mon, 19 Jan 2015 22:46:29 +0000 (14:46 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 19 Jan 2015 22:46:29 +0000 (14:46 -0800)
It can happen that the DisplayObserver methods are called without a
valid Display object passed.

atom/browser/api/atom_api_screen.cc

index 76bf67edfb28039b9214118dfe0739c627eda136..6e5dd716d7fd20d5210409e606821ede0919ad47 100644 (file)
@@ -86,13 +86,21 @@ void Screen::OnDisplayAdded(const gfx::Display& new_display) {
 }
 
 void Screen::OnDisplayRemoved(const gfx::Display& old_display) {
-  displays_.erase(FindById(&displays_, old_display.id()));
+  auto iter = FindById(&displays_, old_display.id());
+  if (iter == displays_.end())
+    return;
+
+  displays_.erase(iter);
   Emit("display-removed", old_display);
 }
 
 void Screen::OnDisplayMetricsChanged(const gfx::Display& display,
                                      uint32_t changed_metrics) {
-  *FindById(&displays_, display.id()) = display;
+  auto iter = FindById(&displays_, display.id());
+  if (iter == displays_.end())
+    return;
+
+  *iter = display;
   Emit("display-metrics-changed", display, MetricsToArray(changed_metrics));
 }