Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: components/metrics/file_metrics_provider.cc

Issue 2742193002: Harden allocator for file-backed memory. (Closed)
Patch Set: addressed final review comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/metrics/file_metrics_provider.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/metrics/file_metrics_provider.cc
diff --git a/components/metrics/file_metrics_provider.cc b/components/metrics/file_metrics_provider.cc
index 24cfa9b761368155ec1698486ceef795f8a89a82..137e9dc895bd47464e8b3727a22eb19ae1a524af 100644
--- a/components/metrics/file_metrics_provider.cc
+++ b/components/metrics/file_metrics_provider.cc
@@ -335,10 +335,18 @@ FileMetricsProvider::AccessResult FileMetricsProvider::CheckAndMapMetricSource(
return ACCESS_RESULT_INVALID_CONTENTS;
}
- // Create an allocator for the mapped file. Ownership passes to the allocator.
- source->allocator.reset(new base::PersistentHistogramAllocator(
+ // Map the file and validate it.
+ std::unique_ptr<base::PersistentMemoryAllocator> memory_allocator =
base::MakeUnique<base::FilePersistentMemoryAllocator>(
- std::move(mapped), 0, 0, base::StringPiece(), read_only)));
+ std::move(mapped), 0, 0, base::StringPiece(), read_only);
+ if (memory_allocator->GetMemoryState() ==
+ base::PersistentMemoryAllocator::MEMORY_DELETED) {
+ return ACCESS_RESULT_MEMORY_DELETED;
+ }
+
+ // Create an allocator for the mapped file. Ownership passes to the allocator.
+ source->allocator = base::MakeUnique<base::PersistentHistogramAllocator>(
+ std::move(memory_allocator));
return ACCESS_RESULT_SUCCESS;
}
« no previous file with comments | « components/metrics/file_metrics_provider.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698