summaryrefslogtreecommitdiff
blob: 9c00b83f4afddd32a191467508e2a9bca25c164e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From 9e0bf3bb5954cc8848e33d6806a67e75199e7ceb Mon Sep 17 00:00:00 2001
From: Stephan Hartmann <stha09@googlemail.com>
Date: Tue, 16 Feb 2021 19:51:38 +0000
Subject: [PATCH] fix crash if smooth_thread_history_ is empty

https://crrev.com/11ce5ea added smooth_thread_history_, but does
not handle an empty std::map correctly. Decrementing iterator
returned by lower_bound() only works, if the map is non-empty.

Bug: 1169818
Change-Id: If75c3d4c7412e77b3ae6c3e68fa3e3821dc75764
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2692534
Reviewed-by: Behdad Bakhshinategh <behdadb@chromium.org>
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Behdad Bakhshinategh <behdadb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#854397}
---

diff --git a/cc/metrics/compositor_frame_reporting_controller.cc b/cc/metrics/compositor_frame_reporting_controller.cc
index 6713366..dec573d1 100644
--- a/cc/metrics/compositor_frame_reporting_controller.cc
+++ b/cc/metrics/compositor_frame_reporting_controller.cc
@@ -440,10 +440,12 @@
   }
 
   // keep the history for the last 3 seconds.
-  auto expired_smooth_thread = smooth_thread_history_.lower_bound(
-      Now() - base::TimeDelta::FromSeconds(3))--;
-  smooth_thread_history_.erase(smooth_thread_history_.begin(),
-                               expired_smooth_thread);
+  if (!smooth_thread_history_.empty()) {
+    auto expired_smooth_thread = smooth_thread_history_.lower_bound(
+        Now() - base::TimeDelta::FromSeconds(3))--;
+    smooth_thread_history_.erase(smooth_thread_history_.begin(),
+                                 expired_smooth_thread);
+  }
 
   // Only trackes the history if there is a change in smooth_thread_
   if (current_smooth_thread != GetSmoothThread()) {