diff options
author | bcwhite <bcwhite@chromium.org> | 2016-02-02 09:57:41 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-02 17:59:02 +0000 |
commit | 373ce2117c573c846aab29b4b2dbd1d0c74434f9 (patch) | |
tree | 98e6744abe3d5c4f2363325d3f2004d02fd3e3d5 | |
parent | acec8d955318e24f9a08e7f1cda4ad83dd6660ee (diff) | |
download | chromium_src-373ce2117c573c846aab29b4b2dbd1d0c74434f9.zip chromium_src-373ce2117c573c846aab29b4b2dbd1d0c74434f9.tar.gz chromium_src-373ce2117c573c846aab29b4b2dbd1d0c74434f9.tar.bz2 |
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}
-rw-r--r-- | base/metrics/statistics_recorder.cc | 8 |
1 files changed, 7 insertions, 1 deletions
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; } |