Bug 1349746 - Ensure we close media cache's temporary file if the cache shuts down while we're waiting for the FD to arrive. r?jwwang draft
authorChris Pearce <cpearce@mozilla.com>
Thu, 23 Mar 2017 11:20:34 +1300
changeset 503192 aa779da15646c03e08685fe895f6cce97d82cb54
parent 502997 e03e0c60462c775c7558a1dc9d5cf2076c3cd1f9
child 550377 e928b9ac74f07ec7d0bd58bf015f18d4b19d430a
push id50524
push userbmo:cpearce@mozilla.com
push dateThu, 23 Mar 2017 00:02:35 +0000
reviewersjwwang
bugs1349746
milestone55.0a1
Bug 1349746 - Ensure we close media cache's temporary file if the cache shuts down while we're waiting for the FD to arrive. r?jwwang In some situations the MediaCache can be shutdown while we're waiting for the parent process to return a temporary file. We should close the temporary file so that we don't leak it in this situation. MozReview-Commit-ID: E3pgO8nWDB8
dom/media/FileBlockCache.cpp
--- a/dom/media/FileBlockCache.cpp
+++ b/dom/media/FileBlockCache.cpp
@@ -20,16 +20,27 @@ LazyLogModule gFileBlockCacheLog("FileBl
 
 void
 FileBlockCache::SetCacheFile(PRFileDesc* aFD)
 {
   MOZ_ASSERT(NS_IsMainThread());
   FBC_LOG(LogLevel::Debug,
           ("FileBlockCache::SetFD(aFD=%p) mIsOpen=%d", aFD, mIsOpen));
 
+  if (!mIsOpen) {
+    // The cache has been shutdown while we were waiting for the file
+    // descriptor to come back in from the parent process.
+    if (aFD) {
+      // Close the file handle so it doesn't leak.
+      PR_Close(aFD);
+    }
+    mInitPromise->Reject(NS_ERROR_FAILURE, __func__);
+    return;
+  }
+
   if (!aFD) {
     // Failed to get a temporary file. Shutdown.
     mInitPromise->Reject(NS_ERROR_FAILURE, __func__);
     Close();
     return;
   }
   {
     MonitorAutoLock lock(mFileMonitor);