From b89b0e13a409d89c9bd207fc04b82f46a7b22ec1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 29 Jul 2016 19:34:20 +1000 Subject: [PATCH] Bug 1276724 - Make two url-classifier allocations fallible. r=gcp. This addresses two crashes in the top #75 on 47.0.1. --- toolkit/components/url-classifier/HashStore.cpp | 4 +++- toolkit/components/url-classifier/LookupCache.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/toolkit/components/url-classifier/HashStore.cpp b/toolkit/components/url-classifier/HashStore.cpp index d57038dfcf436..ed1822d42ec70 100644 --- a/toolkit/components/url-classifier/HashStore.cpp +++ b/toolkit/components/url-classifier/HashStore.cpp @@ -787,7 +787,9 @@ HashStore::WriteAddPrefixes(nsIOutputStream* aOut) { nsTArray 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()); diff --git a/toolkit/components/url-classifier/LookupCache.cpp b/toolkit/components/url-classifier/LookupCache.cpp index 1d29fccd30c02..f0220bed9eac5 100644 --- a/toolkit/components/url-classifier/LookupCache.cpp +++ b/toolkit/components/url-classifier/LookupCache.cpp @@ -564,7 +564,9 @@ LookupCache::ConstructPrefixSet(AddPrefixArray& aAddPrefixes) Telemetry::AutoTimer timer; nsTArray 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());