From 373ce2117c573c846aab29b4b2dbd1d0c74434f9 Mon Sep 17 00:00:00 2001 From: bcwhite Date: Tue, 2 Feb 2016 09:57:41 -0800 Subject: Lock histograms during iteration. Mac builds are crashing due to invalid dereferences with the only explanation I can see being a race-condition of iterating over the tree while it is being added to on another thread. The alternative would be a larger change that goes back to fetching a vector of histograms (GetHistograms) in one shot within the calling code. I've left the NULL in (like the rest of the file) rather than change it to nullptr because this is just a quick bug-fix. BUG=583287 Review URL: https://codereview.chromium.org/1659913002 Cr-Commit-Position: refs/heads/master@{#372981} --- base/metrics/statistics_recorder.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc index 1bfa348..12e4489 100644 --- a/base/metrics/statistics_recorder.cc +++ b/base/metrics/statistics_recorder.cc @@ -48,7 +48,12 @@ StatisticsRecorder::HistogramIterator::~HistogramIterator() {} StatisticsRecorder::HistogramIterator& StatisticsRecorder::HistogramIterator::operator++() { const HistogramMap::iterator histograms_end = histograms_->end(); - while (iter_ != histograms_end) { + if (iter_ == histograms_end || lock_ == NULL) + return *this; + + base::AutoLock auto_lock(*lock_); + + for (;;) { ++iter_; if (iter_ == histograms_end) break; @@ -58,6 +63,7 @@ StatisticsRecorder::HistogramIterator::operator++() { } break; } + return *this; } -- cgit v1.1