Bug 1250439 - preven memory leak in Classifier::GetLookupCache. r=gcp
authorBogdan Postelnicu <bogdan.postelnicu@softvision.ro>
Wed, 24 Feb 2016 13:34:10 +0200
changeset 321718 8441283083be0dcf4baa36ca5d20ac9b6f73505c
parent 321717 94abde4bfd895edba6436f90d328da5e1c0e8610
child 321719 dbfd3ae13ac8230f7c547a51994cfc4d524b9cb8
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
bugs1250439
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1250439 - preven memory leak in Classifier::GetLookupCache. r=gcp MozReview-Commit-ID: BlROMq9gFzj
toolkit/components/url-classifier/Classifier.cpp
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -687,30 +687,30 @@ LookupCache *
 Classifier::GetLookupCache(const nsACString& aTable)
 {
   for (uint32_t i = 0; i < mLookupCaches.Length(); i++) {
     if (mLookupCaches[i]->TableName().Equals(aTable)) {
       return mLookupCaches[i];
     }
   }
 
-  LookupCache *cache = new LookupCache(aTable, mStoreDirectory);
+  UniquePtr<LookupCache> cache(new LookupCache(aTable, mStoreDirectory));
   nsresult rv = cache->Init();
   if (NS_FAILED(rv)) {
     return nullptr;
   }
   rv = cache->Open();
   if (NS_FAILED(rv)) {
     if (rv == NS_ERROR_FILE_CORRUPTED) {
       Reset();
     }
     return nullptr;
   }
-  mLookupCaches.AppendElement(cache);
-  return cache;
+  mLookupCaches.AppendElement(cache.get());
+  return cache.release();
 }
 
 nsresult
 Classifier::ReadNoiseEntries(const Prefix& aPrefix,
                              const nsACString& aTableName,
                              uint32_t aCount,
                              PrefixArray* aNoiseEntries)
 {