From f9ee3990f0eaf1bb340447bbd7d6c196e2178ab9 Mon Sep 17 00:00:00 2001 From: "mbelshe@chromium.org" Date: Tue, 22 Jun 2010 17:36:07 +0000 Subject: Safeguard histogram accesses against null pointers. This can happen when various tasks run as the static destructors for histograms are concurrently running. BUG=none TEST=none Review URL: http://codereview.chromium.org/2873009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50478 0039d316-1c4b-4281-b951-d872f2087c98 --- base/histogram.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/base/histogram.h b/base/histogram.h index edcb629..a11e293 100644 --- a/base/histogram.h +++ b/base/histogram.h @@ -61,7 +61,7 @@ static scoped_refptr counter = Histogram::FactoryGet( \ name, min, max, bucket_count, Histogram::kNoFlags); \ DCHECK_EQ(name, counter->histogram_name()); \ - counter->Add(sample); \ + if (counter.get()) counter->Add(sample); \ } while (0) #define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ @@ -73,7 +73,7 @@ static scoped_refptr counter = Histogram::FactoryTimeGet( \ name, min, max, bucket_count, Histogram::kNoFlags); \ DCHECK_EQ(name, counter->histogram_name()); \ - counter->AddTime(sample); \ + if (counter.get()) counter->AddTime(sample); \ } while (0) // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES. @@ -81,7 +81,7 @@ static scoped_refptr counter = Histogram::FactoryTimeGet( \ name, min, max, bucket_count, Histogram::kNoFlags); \ DCHECK_EQ(name, counter->histogram_name()); \ - if ((sample) < (max)) counter->AddTime(sample); \ + if ((sample) < (max) && counter.get()) counter->AddTime(sample); \ } while (0) // Support histograming of an enumerated value. The samples should always be @@ -91,14 +91,14 @@ static scoped_refptr counter = LinearHistogram::FactoryGet( \ name, 1, boundary_value, boundary_value + 1, Histogram::kNoFlags); \ DCHECK_EQ(name, counter->histogram_name()); \ - counter->Add(sample); \ + if (counter.get()) counter->Add(sample); \ } while (0) #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ static scoped_refptr counter = CustomHistogram::FactoryGet( \ name, custom_ranges, Histogram::kNoFlags); \ DCHECK_EQ(name, counter->histogram_name()); \ - counter->Add(sample); \ + if (counter.get()) counter->Add(sample); \ } while (0) @@ -161,7 +161,7 @@ static scoped_refptr counter = Histogram::FactoryTimeGet( \ name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \ DCHECK_EQ(name, counter->histogram_name()); \ - counter->AddTime(sample); \ + if (counter.get()) counter->AddTime(sample); \ } while (0) // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES. @@ -169,7 +169,7 @@ static scoped_refptr counter = Histogram::FactoryTimeGet( \ name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \ DCHECK_EQ(name, counter->histogram_name()); \ - if ((sample) < (max)) counter->AddTime(sample); \ + if ((sample) < (max) && counter.get()) counter->AddTime(sample); \ } while (0) #define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ @@ -185,7 +185,7 @@ static scoped_refptr counter = Histogram::FactoryGet( \ name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \ DCHECK_EQ(name, counter->histogram_name()); \ - counter->Add(sample); \ + if (counter.get()) counter->Add(sample); \ } while (0) #define UMA_HISTOGRAM_MEMORY_KB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ @@ -202,14 +202,14 @@ name, 1, boundary_value, boundary_value + 1, \ Histogram::kUmaTargetedHistogramFlag); \ DCHECK_EQ(name, counter->histogram_name()); \ - counter->Add(sample); \ + if (counter.get()) counter->Add(sample); \ } while (0) #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ static scoped_refptr counter = CustomHistogram::FactoryGet( \ name, custom_ranges, Histogram::kUmaTargetedHistogramFlag); \ DCHECK_EQ(name, counter->histogram_name()); \ - counter->Add(sample); \ + if (counter.get()) counter->Add(sample); \ } while (0) //------------------------------------------------------------------------------ -- cgit v1.1