Bug 1276724 - Make two url-classifier allocations fallible. r=gcp. a=lizzard
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 29 Jul 2016 19:34:20 +1000
changeset 342303 d28c4c3dc45720eb7558c6dd944800d206a34274
parent 342302 f3beb0f28c64a59f73ada9e7005544453ffea139
child 342304 120810e0a2894aae5eea2d0b971a668ce78b55c3
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp, lizzard
bugs1276724
milestone49.0
Bug 1276724 - Make two url-classifier allocations fallible. r=gcp. a=lizzard This addresses two crashes in the top #75 on 47.0.1.
toolkit/components/url-classifier/HashStore.cpp
toolkit/components/url-classifier/LookupCache.cpp
--- a/toolkit/components/url-classifier/HashStore.cpp
+++ b/toolkit/components/url-classifier/HashStore.cpp
@@ -782,17 +782,19 @@ HashStore::ReadSubPrefixes()
 }
 
 // Split up PrefixArray back into the constituents
 nsresult
 HashStore::WriteAddPrefixes(nsIOutputStream* aOut)
 {
   nsTArray<uint32_t> chunks;
   uint32_t count = mAddPrefixes.Length();
-  chunks.SetCapacity(count);
+  if (!chunks.SetCapacity(count, fallible)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   for (uint32_t i = 0; i < count; i++) {
     chunks.AppendElement(mAddPrefixes[i].Chunk());
   }
 
   nsresult rv = ByteSliceWrite(aOut, chunks);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/toolkit/components/url-classifier/LookupCache.cpp
+++ b/toolkit/components/url-classifier/LookupCache.cpp
@@ -559,17 +559,19 @@ static void EnsureSorted(T* aArray)
 #endif
 
 nsresult
 LookupCache::ConstructPrefixSet(AddPrefixArray& aAddPrefixes)
 {
   Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_PS_CONSTRUCT_TIME> timer;
 
   nsTArray<uint32_t> array;
-  array.SetCapacity(aAddPrefixes.Length());
+  if (!array.SetCapacity(aAddPrefixes.Length(), fallible)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   for (uint32_t i = 0; i < aAddPrefixes.Length(); i++) {
     array.AppendElement(aAddPrefixes[i].PrefixHash().ToUint32());
   }
   aAddPrefixes.Clear();
 
 #ifdef DEBUG
   // PrefixSet requires sorted order