Bug 1054813: Add some missing MutexAutoLocks in nsZipReaderCache; r=mwu
authorAaron Klotz <aklotz@mozilla.com>
Tue, 19 Aug 2014 12:11:03 -0600
changeset 200386 61602e8912a6e85e6ae04738d371cde8d8d8e0cc
parent 200385 9833f49704364564c5099c3d30089475f35b40fa
child 200387 7e5735c7a767b2fb15247328b08d293cee051e8c
push id47889
push useraklotz@mozilla.com
push dateTue, 19 Aug 2014 19:33:00 +0000
treeherdermozilla-inbound@61602e8912a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs1054813
milestone34.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 1054813: Add some missing MutexAutoLocks in nsZipReaderCache; r=mwu
modules/libjar/nsJAR.cpp
--- a/modules/libjar/nsJAR.cpp
+++ b/modules/libjar/nsJAR.cpp
@@ -1142,16 +1142,18 @@ nsZipReaderCache::GetInnerZip(nsIFile* z
                               nsIZipReader* *result)
 {
   NS_ENSURE_ARG_POINTER(zipFile);
 
   nsCOMPtr<nsIZipReader> outerZipReader;
   nsresult rv = GetZip(zipFile, getter_AddRefs(outerZipReader));
   NS_ENSURE_SUCCESS(rv, rv);
 
+  MutexAutoLock lock(mLock);
+
 #ifdef ZIP_CACHE_HIT_RATE
   mZipCacheLookups++;
 #endif
 
   nsAutoCString uri;
   rv = zipFile->GetNativePath(uri);
   if (NS_FAILED(rv)) return rv;
 
@@ -1184,17 +1186,16 @@ nsZipReaderCache::GetInnerZip(nsIFile* z
 
 NS_IMETHODIMP
 nsZipReaderCache::SetMustCacheFd(nsIFile* zipFile, bool aMustCacheFd)
 {
 #if defined(XP_WIN)
   MOZ_CRASH("Not implemented");
   return NS_ERROR_NOT_IMPLEMENTED;
 #else
-  mMustCacheFd = aMustCacheFd;
 
   if (!aMustCacheFd) {
     return NS_OK;
   }
 
   if (!zipFile) {
     return NS_ERROR_FAILURE;
   }
@@ -1203,16 +1204,19 @@ nsZipReaderCache::SetMustCacheFd(nsIFile
   nsAutoCString uri;
   rv = zipFile->GetNativePath(uri);
   if (NS_FAILED(rv)) {
     return rv;
   }
   uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
 
   MutexAutoLock lock(mLock);
+
+  mMustCacheFd = aMustCacheFd;
+
   nsRefPtr<nsJAR> zip;
   mZips.Get(uri, getter_AddRefs(zip));
   if (!zip) {
     return NS_ERROR_FAILURE;
   }
 
   // Flush the file from the cache if its file descriptor was not cached.
   PRFileDesc* fd = nullptr;
@@ -1383,16 +1387,17 @@ nsZipReaderCache::Observe(nsISupports *a
                           const char *aTopic,
                           const char16_t *aSomeData)
 {
   if (strcmp(aTopic, "memory-pressure") == 0) {
     MutexAutoLock lock(mLock);
     mZips.Enumerate(FindFlushableZip, nullptr);
   }
   else if (strcmp(aTopic, "chrome-flush-caches") == 0) {
+    MutexAutoLock lock(mLock);
     mZips.EnumerateRead(DropZipReaderCache, nullptr);
     mZips.Clear();
   }
   else if (strcmp(aTopic, "flush-cache-entry") == 0) {
     nsCOMPtr<nsIFile> file = do_QueryInterface(aSubject);
     if (!file)
       return NS_OK;