Bug 967941, part 3 - Smart pointerize nsZipReaderCache methods. r=aklotz
authorAndrew McCreight <continuation@gmail.com>
Mon, 24 Feb 2014 17:16:11 -0800
changeset 170657 68c714066b0cacd5602b8ff94a8bd0c44f080aef
parent 170656 ef74212f2e25614500f731f83ccdf444396d9e3b
child 170658 3b32d0f94b57685ad54ba47aa8dadc29c9824bf1
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersaklotz
bugs967941
milestone30.0a1
Bug 967941, part 3 - Smart pointerize nsZipReaderCache methods. r=aklotz
modules/libjar/nsJAR.cpp
--- a/modules/libjar/nsJAR.cpp
+++ b/modules/libjar/nsJAR.cpp
@@ -1105,38 +1105,36 @@ nsZipReaderCache::GetZip(nsIFile* zipFil
 #endif
 
   nsAutoCString uri;
   rv = zipFile->GetNativePath(uri);
   if (NS_FAILED(rv)) return rv;
 
   uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
 
-  nsJAR* zip;
-  mZips.Get(uri, &zip);
+  nsRefPtr<nsJAR> zip;
+  mZips.Get(uri, getter_AddRefs(zip));
   if (zip) {
 #ifdef ZIP_CACHE_HIT_RATE
     mZipCacheHits++;
 #endif
     zip->ClearReleaseTime();
   } else {
     zip = new nsJAR();
-    NS_ADDREF(zip);
     zip->SetZipReaderCache(this);
 
     rv = zip->Open(zipFile);
     if (NS_FAILED(rv)) {
-      NS_RELEASE(zip);
       return rv;
     }
 
     MOZ_ASSERT(!mZips.Contains(uri));
     mZips.Put(uri, zip);
   }
-  *result = zip;
+  zip.forget(result);
   return rv;
 }
 
 NS_IMETHODIMP
 nsZipReaderCache::GetInnerZip(nsIFile* zipFile, const nsACString &entry,
                               nsIZipReader* *result)
 {
   NS_ENSURE_ARG_POINTER(zipFile);
@@ -1152,38 +1150,36 @@ nsZipReaderCache::GetInnerZip(nsIFile* z
   nsAutoCString uri;
   rv = zipFile->GetNativePath(uri);
   if (NS_FAILED(rv)) return rv;
 
   uri.Insert(NS_LITERAL_CSTRING("jar:"), 0);
   uri.AppendLiteral("!/");
   uri.Append(entry);
 
-  nsJAR* zip;
-  mZips.Get(uri, &zip);
+  nsRefPtr<nsJAR> zip;
+  mZips.Get(uri, getter_AddRefs(zip));
   if (zip) {
 #ifdef ZIP_CACHE_HIT_RATE
     mZipCacheHits++;
 #endif
     zip->ClearReleaseTime();
   } else {
     zip = new nsJAR();
-    NS_ADDREF(zip);
     zip->SetZipReaderCache(this);
 
     rv = zip->OpenInner(outerZipReader, entry);
     if (NS_FAILED(rv)) {
-      NS_RELEASE(zip);
       return rv;
     }
 
     MOZ_ASSERT(!mZips.Contains(uri));
     mZips.Put(uri, zip);
   }
-  *result = zip;
+  zip.forget(result);
   return rv;
 }
 
 static PLDHashOperator
 FindOldestZip(const nsACString &aKey, nsJAR* aZip, void* aClosure)
 {
   nsJAR** oldestPtr = static_cast<nsJAR**>(aClosure);
   nsJAR* oldest = *oldestPtr;
@@ -1317,26 +1313,26 @@ nsZipReaderCache::Observe(nsISupports *a
 
     nsAutoCString uri;
     if (NS_FAILED(file->GetNativePath(uri)))
       return NS_OK;
 
     uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
 
     MutexAutoLock lock(mLock);
-    nsJAR* zip;
-    mZips.Get(uri, &zip);
+
+    nsRefPtr<nsJAR> zip;
+    mZips.Get(uri, getter_AddRefs(zip));
     if (!zip)
       return NS_OK;
 
 #ifdef ZIP_CACHE_HIT_RATE
     mZipCacheFlushes++;
 #endif
 
     zip->SetZipReaderCache(nullptr);
 
     mZips.Remove(uri);
-    NS_RELEASE(zip);
   }
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////